A simple program to ask the user to give two numbers and then the program will ask the sum of two numbers and subtract the difference of two numbers using Java programming language.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Program Listing
package test;
/*
* Prof. Jake Rodriguez Pomperada, MAED-IT, MIT
* www.jakerpomperada.com and www.jakerpomperada.blogspot.com
* jakerpomperada@gmail.com
* Bacolod City, Negros Occidental Philippines
*/
import java.util.Scanner;
public class Addition_Subtraction {
public static void main(String[] args) {
// TODO Auto-generated method stub
int first=0, second=0;
Scanner input = new Scanner(System.in);
System.out.println();
System.out.println("\tAddition and Subtraction of Two Numbers in Java");
System.out.println();
System.out.print("\tEnter First Numbers : ");
first = input.nextInt();
System.out.print("\tEnter Two Numbers : ");
second = input.nextInt();
int add = first + second;
int subtract = first - second;
if (first > second) {
subtract = first - second;
} else if (second > first) {
subtract = second - first;
} else if (first == second) {
subtract = first - second;
}
System.out.println();
System.out.println("\tThe Sum of " + first + " and " + second + " is " + add + ".");
System.out.println();
System.out.println("\tThe Difference Between " + first + " and " + second + " is " + subtract + ".");
System.out.println("\n");
System.out.print("\tEnd of Program \n");
System.out.println();
input.close();
}
}
No comments:
Post a Comment