Tuesday, July 22, 2014

Choosing Between Sum, Difference, Product and Average in Java

import java.util.Scanner;
public class abejeroact14 {
public static void main(String[] jda) {
Scanner input = new Scanner(System.in);
int a;
int b;
int c;
System.out.println("Enter the First Value");
a = input.nextInt();
System.out.println("Enter the Second Value");
b = input.nextInt();
System.out.println("Enter the Third Value");
c = input.nextInt();
int sum = a + b + c;
int diff = a - b - c;
int prod = a * b * c;
int ave = (a + b + c) / 3;
int choice;
System.out.println("Enter Your Choice Below\n 1. Sum\n 2. Difference\n 3. Product\n 4. Average");
choice = input.nextInt();
switch (choice)
{
case 1:
{
System.out.println("Sum\t" +sum);
}
break;
case 2:
{
System.out.println("Difference\t" +diff);
}
break;
case 3:
{
System.out.println("Product\t" +prod);
}
break;
case 4:
{
System.out.println("Average\t" +ave);
}
break;
default:
{
System.out.print("Error Code");
}
}
}
}

No comments:

Post a Comment