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

Exercise 7

Create a program that multiplies two numbers together. What is the biggest multiplication that the program is able to calculate?

My Code

public class Multiplication {

    public static void main(String[] args) {

        int a = 1337;
        int b = 42;

        // Program your solution here. Remember to use variables a and b!
        System.out.println(a + " * " + b + " = " + (a * b));
    }

}

I worked the highest number out as 2147483647.

Model code

public class Multiplication {

 

    public static void main(String[] args) {

 

        int a = 1337;

        int b = 42;

 

        // Program your solution here. Remember to use variables a and b!

        int result = a * b;

        String toPrint = a + " * " + b + " = " + result;

        System.out.println(toPrint);

    }

 

}
Leave a Reply

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