Computer Science, asked by anshitripathi61374, 11 months ago

How to write a Java program for finding the product and difference between 17 and 2 using variables

Answers

Answered by iamishitap
4

Answer:

Write a Java program that accepts two integers and then prints the sum, the difference, the product, the average, the distance (the difference between integer), the maximum (the larger of the two integers), the minimum (smaller of the two integers).

Test Data

Input 1st integer: 25 

Input 2nd integer:5

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("Sum of two integers: %d%n", firstInt + secondInt); System.out.printf("Difference of two integers: %d%n", firstInt - secondInt); System.out.printf("Product of two integers: %d%n", firstInt * secondInt); System.out.printf("Average of two integers: %.2f%n", (double) (firstInt + secondInt) / 2); System.out.printf("Distance of two integers: %d%n", Math.abs(firstInt - secondInt)); System.out.printf("Max integer: %d%n", Math.max(firstInt, secondInt)); System

Attachments:
Answered by priyanshududhat
4

Answer:

Refer the code below in explanation column.

Explanation:

import java.io.*;

class your_choice {

public static void main(String[] args){

 int a=17;

 int b=2;

 int product=a*b;

 int difference=a-b;

 System.out.println("Product = "+product);

 System.out.println("Difference = "+difference)

}

}

Mark my answer brainliest if you find it helpful!

Similar questions