Reputation: 93
public class twoTimes
{
public static void main(String[] args)
{
for ( int i=1; i<11; i++);
{
System.out.println("count is" + i);
}
}
}
When I try to display i, java is not able to initialise the variable?
Upvotes: 0
Views: 154
Reputation: 169
public class twoTimes
{
public static void main(String[] args)
{
for ( int i=1; i<11; i++)//; <----- Due to this it is not working
{
System.out.println("count is" + i);
}
}
}
Upvotes: 0
Reputation: 3927
It does not have ; at the end off your statement. It should be something like that:
public class twoTimes
{
public static void main(String[] args)
{
for ( int i=1; i<11; i++)
{
System.out.println("count is" + i);
}
}
}
Upvotes: 0
Reputation: 4219
If you add a ; at the end of the for, it looks like the function/command ended. As specified in the previous answers, removing it will ensure your functionality.
public class twoTimes
{
public static void main(String[] args)
{
for ( int i=1; i<11; i++)
System.out.println("count is" + i);
}
}
}
A semicolon (;) always indicates the point where a command would stop. The same thing happens if you create any method and put a ; after, won't work.
Upvotes: 0
Reputation: 437
Remove the ; at the end of the for loop:
for ( int i=1; i<11; i++); <---------
{
System.out.println("count is" + i);
}
Upvotes: 0
Reputation: 174
Try getting rid of the ( ; ) at the end..
for ( int i=1; i<11; i++);
//-----------------------^^
// Remove that ;
Upvotes: 4