To ICS 11 CSA students @ Xavier University
First Assigment: Write a program that will ask the user to input three numbers, and print the result of sum, max and average.
import javax.swing.JOptionPane;
public class Mark{
public static void main(String args[]){
String firstNum,secondNum,thirdNum;
int num1,num2,num3,sum=0,average=0,max=0;
firstNum = JOptionPane.showInputDialog(“Enter first number”);
secondNum = JOptionPane.showInputDialog(“Enter second number”);
thirdNum = JOptionPane.showInputDialog(“Enter third number”);
num1 = Integer.parseInt(firstNum);
num2 = Integer.parseInt(secondNum);
num3 = Integer.parseInt(thirdNum);
if (num1 > num2) {
max = num1;
}
if (max < num3) {
max = num3;
}
else max = max;
sum = num1+num2+num3;
average = sum/3;
JOptionPane.showMessageDialog(null,
“The sum is ” + sum +
“\nThe maximum is ” + max +
“\nThe average is ” + average,
“Result”, JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}