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

Exercise 6

This program calculates the sum of two numbers. At the beginning of the program two variables are introduced and those variables hold the numbers to be summed.


My code

public class Addition {

    public static void main(String[] args) {

        int a = 1337;
        int b = 42;
        int result = a + b; // Fix this

        String toPrint = a + " + " + b + " = " + result;
        System.out.println(toPrint);

    }

}

Model code

public class Addition {

 

    public static void main(String[] args) {

 

        int a = 1337;

        int b = 42;

        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 *