Thursday, February 26, 2015

Addition of Three Numbers in Java

In this short tutorial I would like to share with you a simple program that I wrote in Java how to add three numbers. What this program will do is very simple it will ask the user to enter three integer number and then our program will find the some of the three numbers given by our user. I also added a function that will ask the user if the user want to continue run the program again by asking the user do you want to continue. I am using Textpad as my text editor for Java and java scanner library class for input and output function in our program. I hope my simple program will help you understand basic programming concepts using Java.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program


Program Listing

import java.util.Scanner;

class addition
{

  public static  int add(int a,int b, int c)
   {
  return(a+b+c);
    }

public static void main(String args[])
{
  Scanner in = new Scanner(System.in);
   char a;
do
 {

 int num1=0,num2=0,num3=0,solve_addition=0;

 System.out.print("\n");
 System.out.println("==============================================");
 System.out.println("||    <<< ADDITION OF THREE NUMBERS  >>>    ||");
 System.out.println("==============================================");
     System.out.print("\n");
     System.out.print("Enter First  Number :=> ");
          num1 = in.nextInt();
          System.out.print("Enter Second Number :=> ");
          num2 = in.nextInt();
          System.out.print("Enter First Number  :=> ");
          num3 = in.nextInt();
          int result = add(num1,num2,num3);
     System.out.println("\n");
 System.out.println("=======================");
 System.out.println("||  DISPLAY RESULT   ||");
 System.out.println("=======================");
 System.out.println("\n");
 System.out.print("The sum of " +num1 + " , " + num2 + " and "
                   + num3 + " is " + result + ".");

          System.out.println("\n\n");
          System.out.print("Do you Want To Continue (Y/N) :=> ");
           a=in.next().charAt(0);

   } while(a=='Y'|| a=='y');
          System.out.println("\n");
          System.out.println("\t ===== END OF PROGRAM ======");
         System.out.println("\n");
}
}


No comments:

Post a Comment