• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you want '\n' , not '/n' .
 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers!!
Works fine now!
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic