P
pmusu
threeInt.java:51: incompatible types
found : int
required: java.lang.String
sum = (number1 + number2 + number3);
^
threeInt.java:54: incompatible types
found : int
required: java.lang.String
average = (number1 + number2 + number3) / 3;
^
threeInt.java:57: incompatible types
found : int
required: java.lang.String
product = (number1 * number2 * number3);
^
3 errors
Tool completed with exit code 1
Here is code:
/* 2.18 Write an application that inputs three integers from the user
and displays the sum, average
, product, smallest and largest of the information in an information
dialog. Note the average
should be in integer. */
// Java Packages
import javax.swing.JOptionPane;
public class threeInt {
// main method begins execution of Java application
public static void main( String args[] )
{
String firstNumber; // first string entered by user
String secondNumber; // second string entered by user
String thirdNumber; // third string entered by user
String sum;
String average;
String product;
String smallest;
String largest;
int number1;
int number2;
int number3;
// read first number from user as a string
firstNumber = JOptionPane.showInputDialog( "Enter first integer:");
// read second number from user as a string
secondNumber = JOptionPane.showInputDialog( "Enter second integer:");
// read third number from user as a string
thirdNumber = JOptionPane.showInputDialog( "Enter third integer:");
// convert numbers from type String to type int
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );
number3 = Integer.parseInt( thirdNumber );
// initialise results to empty String
sum = "";
average = "";
product = "";
smallest = "";
largest = "";
// compute sum
sum = (number1 + number2 + number3);
// compute average
average = (number1 + number2 + number3) / 3;
// compute product
product = (number1 * number2 * number3);
// compute smallest
if (number1 < number2);
if (number1 < number3);
smallest = smallest + "Smallest number is" + number1;
if (number2 < number1);
if (number2 < number3);
smallest = smallest + "Smallest number is" + number2;
if (number3 < number2);
if (number3 < number1);
smallest = smallest + "Smallest number is" + number3;
// compute largest
if (number1 > number2);
if (number1 > number3);
largest = largest + "Largest number is" + number1;
if (number2 > number1);
if (number2 > number3);
largest = largest + "Largest number is" + number2;
if (number3 > number2);
if (number3 > number1);
largest = largest + "Largest number is" + number3;
// Display sum
JOptionPane.showMessageDialog( null, sum, "Sum",
JOptionPane.INFORMATION_MESSAGE );
// Display average
JOptionPane.showMessageDialog( null, average, "Average",
JOptionPane.INFORMATION_MESSAGE );
// Display product
JOptionPane.showMessageDialog( null, product, "Product",
JOptionPane.INFORMATION_MESSAGE );
// Display smallest
JOptionPane.showMessageDialog( null, smallest, "Smallest",
JOptionPane.INFORMATION_MESSAGE );
// Display largest
JOptionPane.showMessageDialog( null, largest, "Largest",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 ); // terminate application
} // end method main
} // end class threeInt
found : int
required: java.lang.String
sum = (number1 + number2 + number3);
^
threeInt.java:54: incompatible types
found : int
required: java.lang.String
average = (number1 + number2 + number3) / 3;
^
threeInt.java:57: incompatible types
found : int
required: java.lang.String
product = (number1 * number2 * number3);
^
3 errors
Tool completed with exit code 1
Here is code:
/* 2.18 Write an application that inputs three integers from the user
and displays the sum, average
, product, smallest and largest of the information in an information
dialog. Note the average
should be in integer. */
// Java Packages
import javax.swing.JOptionPane;
public class threeInt {
// main method begins execution of Java application
public static void main( String args[] )
{
String firstNumber; // first string entered by user
String secondNumber; // second string entered by user
String thirdNumber; // third string entered by user
String sum;
String average;
String product;
String smallest;
String largest;
int number1;
int number2;
int number3;
// read first number from user as a string
firstNumber = JOptionPane.showInputDialog( "Enter first integer:");
// read second number from user as a string
secondNumber = JOptionPane.showInputDialog( "Enter second integer:");
// read third number from user as a string
thirdNumber = JOptionPane.showInputDialog( "Enter third integer:");
// convert numbers from type String to type int
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );
number3 = Integer.parseInt( thirdNumber );
// initialise results to empty String
sum = "";
average = "";
product = "";
smallest = "";
largest = "";
// compute sum
sum = (number1 + number2 + number3);
// compute average
average = (number1 + number2 + number3) / 3;
// compute product
product = (number1 * number2 * number3);
// compute smallest
if (number1 < number2);
if (number1 < number3);
smallest = smallest + "Smallest number is" + number1;
if (number2 < number1);
if (number2 < number3);
smallest = smallest + "Smallest number is" + number2;
if (number3 < number2);
if (number3 < number1);
smallest = smallest + "Smallest number is" + number3;
// compute largest
if (number1 > number2);
if (number1 > number3);
largest = largest + "Largest number is" + number1;
if (number2 > number1);
if (number2 > number3);
largest = largest + "Largest number is" + number2;
if (number3 > number2);
if (number3 > number1);
largest = largest + "Largest number is" + number3;
// Display sum
JOptionPane.showMessageDialog( null, sum, "Sum",
JOptionPane.INFORMATION_MESSAGE );
// Display average
JOptionPane.showMessageDialog( null, average, "Average",
JOptionPane.INFORMATION_MESSAGE );
// Display product
JOptionPane.showMessageDialog( null, product, "Product",
JOptionPane.INFORMATION_MESSAGE );
// Display smallest
JOptionPane.showMessageDialog( null, smallest, "Smallest",
JOptionPane.INFORMATION_MESSAGE );
// Display largest
JOptionPane.showMessageDialog( null, largest, "Largest",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 ); // terminate application
} // end method main
} // end class threeInt