program that reads three nonzero value entered by the user and determines and prints sum, product, average, smallest & largest of three
Write an application that reads three nonzero value entered by the user and determines and prints sum, product, average, smallest & largest of three
import java.util.Scanner.*; import java.util.*; class UserInput { public static void main(String args[]) { Scanner s =new Scanner(System.in); System.out.println("Enter First number : "); int num1=s.nextInt(); System.out.println("Enter Second number : "); int num2=s.nextInt(); System.out.println("Enter Third number : "); int num3=s.nextInt(); int sum =num1+num2+num3; System.out.println("Sum : "+sum); int prod =num1*num2*num3; System.out.println("Product : "+prod); float avg =sum/3; System.out.println("Average : "+avg); if (num1>num2&&num1>num3) System.out.println("num1 is greater"); if (num2>num1&&num2>num3) System.out.println("num2 is greater"); if (num3>num1&&num3>num2) System.out.println("num3 is greater"); if (num1<num2&&num1<num3) System.out.println("num1 is smaller"); if (num2<num1&&num2<num3) System.out.println("num2 is smaller"); if (num3<num1&&num3<num2) System.out.println("num3 is smaller"); } }
0 comments:
Post a Comment