Sunday, February 19, 2017

Addition of Two Numbers in Java

A simple program that I wrote using Java as my programming language that will ask the user to give two numbers and then our program will compute the sum of the two number being provided by our user.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output




Program Listing

addition_two.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package addition_two;


import java.util.Scanner;

/**
 *
 * @authors Jake R. Pomperada and  Jacob Samuel F. Pomperada
 * Date : February 19, 2017  Sunday
 * Language : Java
 * IDE     : NetBeans
 */
public class addition_two {

    /**
     * @param args the command line arguments
     */
   public static int addition_two_number(int n1, int n2) {
      int sum=0;
      
      sum = (n1+n2);

      return sum;
   } 
    void display()
    {
       int num1=0, num2=0, sum_all=0;

        Scanner s = new Scanner(System.in);
     
        System.out.println();
        System.out.println("=== Addition of Two Numbers Using Method in Java === ");
        System.out.println();
      
         System.out.print("Enter First Value : ");
         num1 = s.nextInt();
            
         System.out.print("Enter Second Value : ");
         num2 = s.nextInt();
                 
         sum_all =  addition_two_number((num1,num2);
  
        System.out.println();
        System.out.println("===== DISPLAY RESULTS ======");
        System.out.println();
        System.out.println("The sum of " + num1 + " and "
                     + num2 + " is " + sum_all + ".");

        System.out.println();
        System.out.println("===== END OF PROGRAM ======");
        System.out.println();
    }
    
    public static void main(String[] args)
      {
        // TODO code application logic here
      addition_two demo  = new addition_two();
      demo.display();
            
    }
    
}

No comments:

Post a Comment