Computer Science, asked by Aditi3149, 2 months ago

WAP in java to input 2 numbers from user and print their difference (Always Positive).​

Answers

Answered by mandipadk
0

Answer:

import java.util.Scanner;

public class Exercise9 {

   public static void main(String[] args)

   {

       Scanner in = new Scanner(System.in);

       System.out.print("Input 1st integer: ");

       int firstInt = in.nextInt();

       System.out.print("Input 2nd integer: ");

       int secondInt = in.nextInt();

       System.out.printf("Difference of two integers: %d%n", firstInt - secondInt);

   }

}

Explanation:

Answered by StephenKJ
0

Answer:

import java.util.Scanner;

public class positive_difference {

   public static void main(String args[]){

       Scanner ob = new Scanner(System.in);

       int input_1, input_2, diff;

       System.out.println("Enter the 1st Number ");

       input_1 = ob.nextInt();

       System.out.println("Enter the 2nd Number ");

       input_2 = ob.nextInt();

       diff = input_1 - input_2;

       if (diff<0)

           diff = diff * (-1);

       System.out.println("Their difference = "+diff);

   }

}

Attachments:
Similar questions