• 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

How to judge the character is "a" or "b" or "c"? my code was not to work,Please

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class abc{
public static void main(String args[]){
char ch=' ';
System.out.println("shoiufosdjf");
try{ ch = (char)System.in.read();
}catch(Exception e){
}
if (ch=new char a){
System.out.println("apple");
}
else (ch=new char b]){
System.out.println("bicke");
}
else (ch=new char c){
System.out.println("cake");
}
}
}
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this
public class abc{
public static void main(String args[])
{
char ch=' ';
System.out.println("shoiufosdjf");
try
{
ch = (char)System.in.read();
}
catch(Exception e){
}
if (ch=='a')
{
System.out.println("apple");
}
else if (ch=='b')
{
System.out.println("bicke");
}
else if (ch=='c')
{
System.out.println("cake");
}
}
}

Your need to use "==" instead of "="
Kelly
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic