Looping variable invisible inside the loop?

I have this exercise printing a one-month-calendar in Java. It’s described in the PDF I attached:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x = 1;

		System.out.print("Enter number of days in month: ");
		int tage = sc.nextInt();
		System.out.print("Enter starting day of the week (1=Monday, 7=Sunday): ");
		int ersterTag = sc.nextInt();
		sc.close();

		System.out.print("\n");
		for (int i = 1; i < ersterTag; i++) {
			System.out.print(" |");
		}

		for (int i = ersterTag; i <= tage; i ++); {
			if ((i % 7) == 0) {
				System.out.print("\n");
			} else {
				System.out.print(i + " ");
			}
		}
	}
}

The compiler gives me these errors:

Error:(24, 30) java: cannot find symbol
  symbol:   variable i
  location: class OneMonthCalendar.Main
Error:(27, 50) java: cannot find symbol
  symbol:   variable i
  location: class OneMonthCalendar.Main

So it appears the i variable is invisible inside the loop? Is that suppsode to be the case?

I figured it out - this one measly semicolon again…

for (int i = ersterTag; i <= tage; i ++); {

should be

for (int i = ersterTag; i <= tage; i ++) {
1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.