Adding 2 Number In Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #16
    Kid, after five weeks, either he's gotten the answer himself or he's given up and gone elsewhere. Regardless, we don't just give boilerplate code here and tell the OP to copy/paste.

    Comment

    • Geethu03
      New Member
      • Dec 2006
      • 45

      #17
      Use this i think it will help you. Pls follow this code
      Code:
      import java.io.*;
      public class cal{
        public static void main(String arg[]) throws IOException {
      
      int a=0;
      int b=0;
      int c=0;
      
      DataInputStream ds = new DataInputStream(System.in());
      a =Integer.parseInt(ds.readLine());
      b =Integer.parseInt(ds.readLine());
      c =a+b;
      system.out.println(c);
      }
      Originally posted by LOVE4EVER
      HI PPL

      I DID A SIMPLE PROGRAM THAT ADD 2 NUMBER BUT I AM HAVING PROBLEM IN ENTER THE NUMBER FROM THE USER

      Code:
      import java.io.*;
      public class cal{
      
      
      int a=0;
      int b=0;
      int c=0;
      
      
      a =reader.readLine();
      b =reader.readLine();
      c =a+b;
      system.out.println(c);
      }
      >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>
      the error in the reader.readline ();

      in c++ you just have to write cin>>a>>

      i am new in java and i really dont know what to do

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #18
        Originally posted by Geethu03
        Use this i think it will help you. Pls follow this code
        I bet you didn't read reply #16 by Lahari and no, you don't need DataInputStream s
        when you want to read text from user's input.

        kind regards,

        Jos

        Comment

        • Kid Programmer
          New Member
          • Mar 2008
          • 176

          #19
          Originally posted by Laharl
          Kid, after five weeks, either he's gotten the answer himself or he's given up and gone elsewhere. Regardless, we don't just give boilerplate code here and tell the OP to copy/paste.
          Well he never said he found the answer and it had gone of for long enough. I figured I might as well just end it. If he has questions about my code I can answer them.

          Comment

          Working...