Try the fastest way to create flashcards
Question

What is wrong with the following programs?

  • a
public class ShowErrors {
    public static void main(String[] args) {
        int i;
        int j = 5;

        if (j > 3)
            System.out.println(i + 4);
    }
}
  • b
 public class ShowErrors {
     public static void main(String[] args) {
         for (int i = 0; i < 10; i++);
         System.out.println(i + 4);
     }
 }

Solution

Verified
Answered 2 years ago
Answered 2 years ago

The problem with the program a) is that there is no semicolon at the end of line 8\textbf {no semicolon at the end of line 8}.

On the other hand, the program b) is having a redundant semicolon on line 3 that should be removed\textbf {redundant semicolon on line 3 that should be removed}.

Create a free account to view solutions

Create a free account to view solutions

Recommended textbook solutions

Introduction to Java Programming, Brief 8th Edition by Y. Daniel Liang

Introduction to Java Programming, Brief

8th EditionISBN: 9780132130790 (1 more)Y. Daniel Liang
500 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
961 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions
Introduction to Algorithms 4th Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions

More related questions

1/4

1/7