Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable not found in Java [closed]

Tags:

java

I've just started working with some programming in java. I'm experimenting with loops and I have a problem with a for-loop where I'm having a hard time finding the mistake. Its saying that "i" is not a variable, even though i made it one in just above. Hope you guys can help!

import java.util.Scanner;
public class Loops {
public static void main(String [] args)
{
    Scanner sc = new Scanner(System.in);
    System.out.println("Skriv et tal");
    int a = sc.nextInt();       
    for(int i = 0; i <= 9; i++);
    {
        System.out.println(a + i);

    }
  }
 }
like image 653
user3249267 Avatar asked May 31 '26 09:05

user3249267


1 Answers

 for(int i=0; i<=9;i++);
                    // ^ get rid of this

should be

 for(int i=0; i<=9;i++)

Because of that the for statement ends there and the new block had been started there.

like image 172
Suresh Atta Avatar answered Jun 02 '26 23:06

Suresh Atta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!