I need these questions completed in Java please: 2.16 Write an application that
ID: 3683052 • Letter: I
Question
I need these questions completed in Java please:
2.16 Write an application that asks the user to enter two intergers, obtains them from the user, and displays the larger number followed by the words "is larger". If the numbers are equal, print message "These numbers are equal".
2.17 Write an applicatoin that inputs three intergers from the user and displays the sum, average, product, smallest and largest of the numbers. (The calculation of the average in this exercise whould result in an integer representation of the average.)
Explanation / Answer
Question 1:
Answer
LargeNumber.java
public class LargeNumber {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.Scanner in = new java.util.Scanner(System.in);
System.out.println("Please enter first Integer : ");
int a = in.nextInt();
System.out.println("Please enter second Integer : ");
int b = in.nextInt();
if(a > b){
System.out.println(a + " is Large");
}
else if(b > a){
System.out.println(b + " is Large");
}
else{
System.out.println("These numbers are equal");
}
}
}
Output:
Please enter first Integer :
1
Please enter second Integer :
1
These numbers are equal
Question 2
Answer
IntegerOperation.java
public class IntegerOperation {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.Scanner in = new java.util.Scanner(System.in);
System.out.println("Please enter first Integer : ");
int a = in.nextInt();
System.out.println("Please enter second Integer : ");
int b = in.nextInt();
System.out.println("Please enter third Integer : ");
int c = in.nextInt();
int sum = a + b + c;
System.out.println("The sum of three integers is : "+sum);
int average = sum/3;
System.out.println("The average of three integers is : "+average);
int product = a * b * c;
System.out.println("The product of three integers is : "+product);
if(a > b && a > c){
System.out.println(a + " is Large");
}
else if(b > a && b > c){
System.out.println(b + " is Large");
}
else{
System.out.println(c + " is Large");
}
if(a < b && a < c){
System.out.println(a + " is Small");
}
else if(b < a && b < c){
System.out.println(b + " is Small");
}
else{
System.out.println(c + " is Small");
}
}
}
Output:
Please enter first Integer :
4
Please enter second Integer :
5
Please enter third Integer :
6
The sum of three integers is : 15
The average of three integers is : 5
The product of three integers is : 120
6 is Large
4 is Small
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.