write a program in Java to assign three integers and print their sum and product
Answers
Answer:
import java.util.Scanner;
public class ArithmeticSmallestLargest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1;
int num2;
int num3;
int sum;
int average;
int product;
double largest
System.out.print("Enter First Integer: ");
num1 = input.nextInt();
System.out.print("Enter Second Integer: ");
num2 = input.nextInt();
System.out.print("Enter Third Integer: ");
num3 = input.nextInt();
sum = num1 + num2 + num3;
average = sum / 3;
product = num1 * num2 * num3;
if (largest =num1 > num2 & num2 > num3)
System.out.println(sum);
System.out.println(average);
System.out.println(product);
System.out.println("The biggest number is " + largest);
}
}
Explanation:
HOPE IT HELPS YOU,
THX
Explanation:
This will be closed unless you show some real effort and be clear about the actual problem that you're facing.
– Swapnil
Sep 4, 2014 at 21:21
1
You will quickly learn that SO does not like homework problems.
– royhowie
Sep 4, 2014 at 21:22
Show 5 more comments
3 Answers
ActiveOldestScore
1
import java.util.Scanner; // exercise 2.17 public class ArithmeticSmallestLargest { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num1; int num2; int num3; int sum; int average; int product; int largest; int smallest; System.out.print("Enter First Integer: "); num1 = input.nextInt(); System.out.print("Enter Second Integer: "); num2 = input.nextInt(); System.out.print("Enter Third Integer: "); num3 = input.nextInt(); sum = num1 + num2 + num3; average = sum / 3; product = num1 * num2 * num3; largest = num1; smallest = num1; if(num2 > largest) largest = num2; if(num3 > largest) largest = num3; if(num2 < smallest) smallest = num2; if (num3 < smallest) smallest = num3; System.out.println("The sum is " + sum); System.out.println("The average is " + average); System.out.println("The product is " + product); System.out.println("Largest of three integers is " + largest + " and the smallest is "+ smallest + "."); } }