USING JAVA Write a program that takes 4 numbers (N1, N2, N3 and N4) from the use
ID: 673717 • Letter: U
Question
USING JAVA
Write a program that takes 4 numbers (N1, N2, N3 and N4) from the user and prints a message based on the relationship between the first pair and the second pair of these numbers: 'smaller' if each of N1 and N2 is strictly smaller than each of N3 and N4 'larger' if each of N1 and N2 is larger or equal to each of N3 and N4 'mixed' otherwise - Note that for 'smaller' you must check that N1 is smaller than both N3 and N4 and that at the same time N2 is also smaller than both N3 and N4. Similarly for 'larger' Do not use any sorting methods or functions from Python Examples: for numbers 4, 1,8. 13 (corresponding to N1, N2, N3, N4) it should print 'smaller' (because 4 is smaller than both 8 and 13, and also 1 is smaller than both 8 and 13) for numbers 7,9,0,2 it should print 'bigger' (because 7 is bigger than both 0 and 2; and also 9 is bigger than both 0 and 2) for numbers 8, 1,4, 13 it should print 'mixed' (because the conditions for 'smaller' and 'bigger' are not met: 8 is between 4 and 13)Explanation / Answer
package mani;
import java.util.Scanner;
public class Test {
public static void main(String[] args){
Scanner s=new Scanner(System.in);
System.out.print("Enter the N1: ");
int N1=s.nextInt();
System.out.print("Enter the N2: ");
int N2=s.nextInt();
System.out.print("Enter the N3: ");
int N3=s.nextInt();
System.out.print("Enter the N4: ");
int N4=s.nextInt();
if(N1>N3&&N1>N4&&N2>N3&&N2>N4){
System.out.println("bigger");
}else if(N1<N3&&N1<N4&&N2<N3&&N2<N4){
System.out.println("smaller");
}else{
System.out.println("mixed");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.