Computer Science, asked by pranil777, 8 months ago

write a java program to find the sum and difference of two numbers​

Answers

Answered by IamGenesis
6

import java.util.Scanner;

public class SumAndDifference{

public static void main (String args[]){

Scanner sc = new Scanner(System.in);

System.out.println("Enter two numbers");

int a = sc.nextInt();

int b = sc.nextInt();

System.out.println("Sum is "+(a+b));

System.out.println("Difference is "+(a-b));

}

}

NB: this is written in BlueJ environment

Answered by ayushdasgupta
2

Answer:

//program to find the sum and the difference

import java.io.*;

public class SumDifference

{

     public static void main(String args[])throws IOException

     {

          InputStreamReader read=new InputStreamReader(System.in);

          BufferedReader in=new BufferedReader(read);

          System.out.println("Enter the first number");

          int a=Integer.parseInt(in.readLine());

          System.out.println("Enter the second number");

          int b=Integer.parseInt(in.readLine());

          double sum=0.0,diff=0.0;

          sum=(a+b);

          diff=(a-b);

          System.out.println("The sum of the two numbers="+sum);

          System.out.println("The difference of the two numbers="+diff);

     }    

}

Explanation:

Similar questions