my dog learned polymorphism*
The moose likes Java in General and the fly likes Basic Java Problem....HELP!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Basic Java Problem....HELP!!!!" Watch "Basic Java Problem....HELP!!!!" New topic
Author

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

Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
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


John Bonham was stronger, but Keith Moon was faster.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
I think you want '\n' , not '/n' .


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
Cheers!!
Works fine now!
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basic Java Problem....HELP!!!!