LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2004, 01:57 PM   #1
javastudent
LQ Newbie
 
Registered: Dec 2004
Posts: 1

Rep: Reputation: 0
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
}

}
 
Old 12-17-2004, 02:54 PM   #2
darkRoom
Member
 
Registered: Mar 2004
Location: Valencia, espaņa
Distribution: Slack, Gentoo, Custom
Posts: 162

Rep: Reputation: 30
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

Last edited by darkRoom; 12-18-2004 at 11:45 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java plugin installed correctly for Firefox but not able to view any java applet tvn Linux - Software 10 04-15-2010 02:13 AM
Java Programming: Java Runtime Environment not found when trying to compile murbz Linux - Software 2 03-26-2009 03:04 AM
Web start java not working (java works fine) powadha Debian 5 06-05-2004 12:57 PM
Updated Java... now java apps dont work zidane2010 Linux - Software 6 05-04-2004 08:02 PM
2 Questions: java calling system commands? PERL vs Java? randomx Programming 28 11-28-2003 08:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration