Object-Oriented Programming with Java, part I – Exercise 11

Exercise 11

This program compares two entered integers and outputs the highest one.

My code

import java.util.Scanner;

public class BiggerNumber {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);

        // Implement your program here. Remember to ask the input from user
        System.out.println("Type a number: ");
        int firstNumber = Integer.parseInt(reader.nextLine());
        
        System.out.println("Type another number: ");
        int secondNumber = Integer.parseInt(reader.nextLine());
        
        System.out.println("The bigger number of the two numbers given was: " + Math.max(firstNumber, secondNumber));
    }
}

Model code

import java.util.Scanner;

 

public class BiggerNumber {

 

    public static void main(String[] args) {

        Scanner reader = new Scanner(System.in);

 

        // Implement your program here. Remember to ask the input from user

        System.out.print("Type a number: ");

        int firstNumber = Integer.parseInt(reader.nextLine());

        System.out.print("Type another number: ");

        int secondNumber = Integer.parseInt(reader.nextLine());

 

        System.out.println(""); // an empty line

        System.out.println("The bigger number of the two numbers given was: " + Math.max(firstNumber, secondNumber));

    }

}
Leave a Reply

Your email address will not be published. Required fields are marked *