• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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
reply
    Bookmark Topic Watch Topic
  • New Topic