Oct 26, 2011

Summation Program Java

0 Comment
/ / File Name: Penjumlahan.java
/ / Description: Displays the sum of two numbers Program

/ / using class Scanner
java.util.Scanner import;

public class Addition
{
  / / main method before the execution of java application
  public static void main (String args [])
  {
   / / create Scanner to obtain input from the form
   Scanner input = new Scanner (System.in);

   int number1; / / first number
   int number2; / / the second number
   int sum; / / number of items 1 and 2

   / / cursor 1
   System.out.print ("Enter First Number:");
   / / read input from user number 1
   number1 = input.nextInt ();

   / / cursor 2
   System.out.print ("Enter Second Number:");
   / / read input from user number 2
   number2 = input.nextInt ();

   / / sum numbers
   sum = number1 + number2;

   / / display the sum
   System.out.printf ("Sum is% d \ n", sum);
  } / / End method
} / / End class Addition

0 Comment:

Post a Comment