2. Language Fundamentals

2.1 The following program will compile and run without errors:
package com.acme; // Correct ordering of package and import statements.

import java.util.*;

public class Exercise1 {
    int counter; // This is rather useless

    public static void main(String[] args) { // Correct main signature
        Exercise1 instance = new Exercise1();
        instance.go();
    }

    public void go() {
        int sum = 0;
        // We could just as well have written sum = 100
        // here and removed the if statement below.
        int i = 0;
        while (i<100) {
            if (i == 0) sum = 100;
            sum = sum + i;
            i++;
        }
        System.out.println(sum);
    }
}
2.2 The following program will compile and run without errors:
 // Filename: Temperature.java /* Identifiers and keywords in Java are case-sensitive. Therefore, ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.