write a program in java. to find the difference of two numbers85 and 27 and display their result in the output window
Answers
Required Answer :
Question:
- Write a program in java to find the difference of two numbers 85 and 27 and display their result in the output window.
Program:
This is the required Java program for the question.
public class diffrence
{
public static void main (String [] args)
{
int a=85;
int b=27;
int ans=a-b;
System.out.println("This is the required answer " +ans);
}
}
The output will be as follows:
This is the required answer 58.
Answer:
There are two ways to do this...
Method 1:- By directly printing
package Programmer; //This is an optional statement, it is not necessary to write.
public class Difference {
public static void main (String ar []){
System.out.println("Difference: "+(85-27));
}
}
Method 2:- By storing in the variable.
package Programmer;
public class Difference {
public static void main (String ar []){
int a=85,b=27;
System.out.println("Difference: "+(a-b));
}
}
Method 3:-
package Programmer;
public class Difference {
public static void main (String ar[]){
int a=85,b=27,c;
c=a-b;
System.out.println("Difference: "+c);
}
}
Desired Output:-
- Difference: 58