LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   need java help (https://www.linuxquestions.org/questions/programming-9/need-java-help-267472/)

javastudent 12-17-2004 01:57 PM

need java help
 
I am trying to write a method in a java program and i keep getting an error: '.class' expected. I'm not sure what I am doing wrong...can someone help. Here's what I have:
import java.io.*;

public class ExtraCredit
{
public static void main(String[] args)
{
System.out.print("Please enter a string: ");

//next 2 lines are the setup for reading stuff in from the user
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader console = new BufferedReader(input);
String line = "";

try
{
line = console.readLine();
}
catch(IOException e)
{
System.out.println("Something went wrong with the input");
}
System.out.println(line);
System.out.println(removeConsonants(line));
System.out.println(removeUpperCase(line));
System.out.println(insertSpaces(line));
System.out.println(StringToArray(line));


}


static String removeConsonants(String s)
{
if (s.length () <= 0)
return new String ("");
if (s.charAt (0) == 'b' || s.charAt (0) == 'B' ||
s.charAt (0) == 'c' || s.charAt (0) == 'C' ||
s.charAt (0) == 'd' || s.charAt (0) == 'D' ||
s.charAt (0) == 'f' || s.charAt (0) == 'F' ||
s.charAt (0) == 'g' || s.charAt (0) == 'G' ||
s.charAt (0) == 'h' || s.charAt (0) == 'H' ||
s.charAt (0) == 'j' || s.charAt (0) == 'J' ||
s.charAt (0) == 'k' || s.charAt (0) == 'K' ||
s.charAt (0) == 'l' || s.charAt (0) == 'L' ||
s.charAt (0) == 'm' || s.charAt (0) == 'M' ||
s.charAt (0) == 'n' || s.charAt (0) == 'N' ||
s.charAt (0) == 'p' || s.charAt (0) == 'P' ||
s.charAt (0) == 'q' || s.charAt (0) == 'Q' ||
s.charAt (0) == 'r' || s.charAt (0) == 'R' ||
s.charAt (0) == 's' || s.charAt (0) == 'S' ||
s.charAt (0) == 't' || s.charAt (0) == 'T' ||
s.charAt (0) == 'v' || s.charAt (0) == 'V' ||
s.charAt (0) == 'w' || s.charAt (0) == 'W' ||
s.charAt (0) == 'x' || s.charAt (0) == 'X' ||
s.charAt (0) == 'y' || s.charAt (0) == 'Y' ||
s.charAt (0) == 'z' || s.charAt (0) == 'Z')
return removeConsonants (s.substring (1));
return s.charAt (0) + removeConsonants (s.substring (1));
}
static String removeUpperCase(String s)
{

if (s.length () <= 0)
return new String ("");
if (s.charAt (0) == 'A' || s.charAt (0) == 'B' ||
s.charAt (0) == 'C' || s.charAt (0) == 'D' ||
s.charAt (0) == 'E' || s.charAt (0) == 'F' ||
s.charAt (0) == 'G' || s.charAt (0) == 'H' ||
s.charAt (0) == 'I' || s.charAt (0) == 'J' ||
s.charAt (0) == 'K' || s.charAt (0) == 'L' ||
s.charAt (0) == 'M' || s.charAt (0) == 'N' ||
s.charAt (0) == 'O' || s.charAt (0) == 'P' ||
s.charAt (0) == 'Q' || s.charAt (0) == 'R' ||
s.charAt (0) == 'S' || s.charAt (0) == 'T' ||
s.charAt (0) == 'U' || s.charAt (0) == 'V' ||
s.charAt (0) == 'W' || s.charAt (0) == 'X' ||
s.charAt (0) == 'Y' || s.charAt (0) == 'Z')
return removeUpperCase (s.substring (1));
return s.charAt (0) + removeUpperCase (s.substring (1));
}
static String insertSpaces(String s)
{
String temp = "" + s.charAt(0);
for(int i = 1; i < s.length(); i++)
{
temp += " " + s.charAt(i);
}
return temp;
}
static char[] StringToArray(String s)
{
char[] data = new char[s.length()];
for(int i = 0; i < s.length(); i++)
{
data[i] = s.charAt(i);
}
return data[]; //this is where I am getting the error
}

}

darkRoom 12-17-2004 02:54 PM

When you return the array:
Code:

return data[]
You don't need the []:
Code:

return data
Code tags help when reading code ;) - so there might be other mistakes . .

happy learning


All times are GMT -5. The time now is 04:05 PM.