correct my program please.

Discussion in 'Java' started by joon, Jul 8, 2003.

  1. joon

    joon Guest

    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");
    joon, Jul 8, 2003
    #1
    1. Advertising

  2. 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.

    > 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");
    Gilles Dubochet, Jul 8, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. joon
    Replies:
    1
    Views:
    509
    Roedy Green
    Jul 8, 2003
  2. KK
    Replies:
    2
    Views:
    516
    Big Brian
    Oct 14, 2003
  3. Replies:
    3
    Views:
    271
    Nick Keighley
    Mar 22, 2007
  4. Replies:
    5
    Views:
    324
    Jim Langston
    Jun 15, 2007
  5. Replies:
    4
    Views:
    346
    osmium
    Oct 19, 2008
Loading...

Share This Page