Given five integers as input, display each in the order entered by the user with
ID: 3670391 • Letter: G
Question
Given five integers as input, display each in the order entered by the user with the character '>', '<', or '=' in between each pair of numbers that accurately represents their relationship.
Only material from the first four chapters of the book may be used in this assignment. The use of any logical operators, relational operators, or selection constructs would violate this requirement and result in no credit being awarded for your effort. You will not need to use math.h on this assignment.
Example Execution #1: Enter the five integer values: 4 8 9 0 3 4 < 8 < 9 > 0 < 3
Example Execution #2: Enter the five integer values: 2 2 3 3 2 2 = 2 < 3 = 3 > 2
Example Execution #3: Enter the five integer values: 0 0 0 0 0 0 = 0 = 0 = 0 = 0
Example Execution #4: Enter the five integer values: 5 4 3 2 1 5 > 4 > 3 > 2 > 1
Explanation / Answer
import java.util.Scanner;
Class Printing
{
public static void main(String args[])
{
int a[5];
Scanner in = new Scanner(System.in);
//reading integers and store it in to array
System.out.printf("Enter the 5 integer values one by one");
for(int i=0;i<4;i++)
{
a[i] = in.nextInt();
}
//checking two neighbor numbers relationship and prints it
System.out.printf(a[0]);
for( i=0;i<4;i++)
{
if(a[i]==a[i+1])
{
System.out.printf("="+a[i+1]);
}
elseIf(a[i]<a[i+1])
{
System.out.printf(("<"+a[i+1]);
}
else
{
System.out.printf((">"+a[i+1]);
}
}//for
}//main
}//class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.