Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question3: (18 points: 4 points for inputs, 2 points for each outputs) Write a J

ID: 3741883 • Letter: Q

Question

Question3: (18 points: 4 points for inputs, 2 points for each outputs) Write a Java program that accepts two integers from the user and then prints the sum, the difference, the product, the average, the distance (assuming the two entered numbers are &y coordinates) from the origin, the maximum (the larger of the two integers), the minimum (smaller of the two integers). Should have something similar to Input 1st integer: 31 Input 2nd integer: 39 Sum of two integers: 70 Difference of two integers: -8 Product of two integers: 1209 Average of two integers: 35.00 distance49.8196748283246 Distance of two integers: 8 Max integer: 39 Min integer: 31

Explanation / Answer

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int one, two;

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

one = sc.nextInt();

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

two = sc.nextInt();

System.out.println("Sum of two intgers: "+(one+two));

System.out.println("Difference of two integers: "+(one-two));

System.out.println("Product of two integers: "+(one*two));

System.out.println("Average of two integers: "+((one+two)/2.0));

System.out.println("Distance : "+Math.sqrt(one*one + two*two));

System.out.println("Distance of two integers: "+Math.abs(one-two));

if(one < two)

{

int temp = one;

one = two;

two = temp;

}

System.out.println("Max integer: "+one);

System.out.println("Min integer: "+two);

}

}

/*SAMPLE OUTPUT

Input 1st integer: 31

Input 2nd integer: 39

Sum of two intgers: 70

Difference of two integers: -8

Product of two integers: 1209

Average of two integers: 35.0

Distance : 49.8196748283246

Distance of two integers: 8

Max integer: 39

Min integer: 31

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote