Results 1 to 3 of 3
  1. #1
    jhuwalker is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default New To Java - Input Number Won't Prompt, Wrong Result

    A simple program that compiled success, but can not input second number, no prompt. number doesn't match the first number input at keyboard with display on output. Thanks

    ========================
    /* Enter two number at prompt
    * Add both number
    * Print out Total
    *
    * 1/31/2011
    * Code Name Add2Number.java
    */

    import java.io.*;

    class Add2Number {
    public static void main(String[] args)
    throws java.io.IOException {
    int n1, n2, Total;

    System.out.println("Enter Your First Number:");
    n1 = (int) System.in.read();
    System.out.println("Enter Your Second Number:");
    n2 = (int) System.in.read();

    Total = n1 + n2;
    System.out.println("n1 = " + n1);
    System.out.println("n2 = " + n2);

    System.out.println("Total = " + Total);
    }
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Try using a scanner, it will make it simpler, Scanner (Java Platform SE 6)

  3. #3
    jhuwalker is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Replies: 5
    Last Post: 05-10-2010, 07:42 AM
  2. Replies: 8
    Last Post: 06-27-2009, 05:35 PM
  3. convert getValue result in a 4 digit number
    By roseline43 in forum New To Java
    Replies: 0
    Last Post: 09-02-2008, 08:44 PM
  4. input prompt
    By angelbaby21 in forum New To Java
    Replies: 8
    Last Post: 08-25-2008, 04:22 AM
  5. handle wrong input int/null
    By Camden in forum New To Java
    Replies: 1
    Last Post: 12-16-2007, 09:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •