Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic Java Problem....HELP!!!!

 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there folks.
I'm using JBuilder 6 Enterprise edition.
I'm trying to compile the following code:-

import java.io.IOException;
class InputDemo {
public static void main(String args[]) {
try {
// Input a single character
System.out.println("Type a character:");
char ch = (char)System.in.read();
System.out.println("You entered: " + ch);
// Throw out new line
while (ch != '/n')
ch = (char)System.in.read();
// Input a string
System.out.println("Type a string:");
StringBuffer s = new StringBuffer();
while ((ch = (char)System.in.read()) != '/n')
s.append(ch);
System.out.println("You entered: " + s);
} catch (IOException e) {
System.out.println("Input error detected");
}
}
}

But when i try and compile this, i get the following error messages:-
"InputDemo.java": Error #: 106 : unclosed character literal at line 11, column 18"
&
"InputDemo.java": Error #: 106 : unclosed character literal at line 16, column 48

Line 11 is - while (ch != '/n')
Line 16 is -
while ((ch = (char)System.in.read()) != '/n')
Does anybody know why i'm getting these erors??

Any help would be GREATLY appreciated
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you want '\n' , not '/n' .
 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers!!
Works fine now!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve115,
Please change your name to be compliant with JavaRanch's naming policy.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic