correct my program please.

J

joon

here is my program
please, correct my program , there are many errors. but i don't know.
please, correct me.


--------------------------------------------------------------------------------
import. Java.io.*;
import. Java.text.NumberFormat;

public class commander

public. static.void man(String[]args)throws IOException

BufferedReader in =
new BufferedReader(New InputStreamReader(Systemin));

int (commander);

System.out.println("Enter your code");
code = integer.parseint(in.readLine());

switch(commander)
{

case 1:
System.out.println("The status of president of United States);
break;
case 2:
System.out.println("The status of secretary of Defense);
break;
case 3:
System.out.println("The status of the Air force);
break;
case 4:
System.out.println("The status of Air force chief staff);
break;
case 5:
System.out.println("The status of Air university commander);
break;
case 6:
System.out.println("The status of Air commader);
break;

default:
System.out.println(" The status of commander is children");
 
G

Gilles Dubochet

Hello,

You would have been better off working a little bit more on your code
before posting it on a newsgroup. By the way :

Java is case sensitive (java.io not Java.io) (and as a convention, class
names should be capitalized while variables should not).

You need to define precisely the scope of your blocks (classes, methods,
control structures ...) with "{}" characters.

Java is not self-correcting, make sure no letters are missing (main not
man).

Dots should not be added randomly to your code, they have a precise
signification related to object-oriented programming.

But well, here is the working code :

import java.io.*;
public class Commander {
public static void main(String[]args) throws IOException {
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your code :");
try {
int code = Integer.parseInt(in.readLine());
switch(code) {
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;
case 3:
System.out.println("Three");
break;
case 4:
System.out.println("Four");
break;
case 5:
System.out.println("Five");
break;
case 6:
System.out.println("Six");
break;
default:
System.out.println("Whatever");
}
} catch (NumberFormatException exception) {
System.out.println("You did not enter a number");
}
}
}

Good luck with java ... and buy a good book on the subject (Learning
Java; Patrick Niemeyer & Jonathan Kundsen; O'Reilly & Associates, Inc;
ISBN 1-56592-718-4 for example), it helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top