197k views
5 votes
3. Write a program that allows entering a whole number and compares the entered number with 4300; so it prints the messages Number is greater than 4300". Number is less than 4300" or Number is equal to 4300"! (Note: we must use the if else statement of conditional branching and the input function to enter the whole number).​

1 Answer

5 votes

Answer and Explanation:

See the attached image for a formatted version of the code.

I have used Java for this example.

See the comments in the code for an explanation of what each line of code does.

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int num = 0;

System.out.print("Please input a number: ");

num = input.nextInt();

if(num > 4300) {

System.out.println("Number is greater than 4300");

} else if(num < 4300) {

System.out.println("Number is less than 4300");

} else {

System.out.println("Number is equal to 4300");

}

}

}

3. Write a program that allows entering a whole number and compares the entered number-example-1
User R R
by
7.4k points