Java program for subtraction of 2 number

Java program for subtraction of 2 number

Program:-

import java.util.Scanner;

class group{
public static void main(String ang[]){
Scanner data= new Scanner(System.in);
int num1, num2, result;
// Read 1st number
System.out.println("Enter 1st number");
num1=data.nextInt();
// Read 2nd number
System.out.println("Enter 2nd number");
num2=data.nextInt();
// subtraction
result=num1-num2;
System.out.println("Anwser:"+result);
}
}


Output:-

Enter 1st number
15
Enter 2nd number
5
Answer:10

Output:-

Enter 1st number
-81
Enter 2nd number
58
Answer:-139

Output:-

Enter 1st number
-45
Enter 2nd number
-56
Answer:11

Output:-

Enter 1st number
-15
Enter 2nd number
26
Answer:-41


Learn Java:-
Java codes

Java Programs:-
List of Java Programs

One Comment

  1. This is the last Line and focus on the spelling of "ANSWER"

    System.out.println("Anwser:"+result);

    And in all the Outputs Spellings are
    Answer:10
    Answer:-139
    Answer:11
    Answer:-41


    How this Could be possible.
    please remove this Error.

    ReplyDelete

Add your comments here

Back to Top