+ 3
Why is the error coming in this program?
public class Program { public static void main(String[] args) { for (int i=1; i<=10; i++); { System.out.println (i); } } }
11 odpowiedzi
+ 6
Sonam Kumari semicolons in general shows the compiler where an instruction ends and where the next instruction begins. The for loop itself requires the parentheses for the condition immediately followed by the constructs { what it is you wanted the program to do } So the semicolon actually interfered with and ended believing it had nothing more to do.
+ 4
The problem is in your for loop which u added at the end of statement . This errror is coming because when you use for loop it omit single statement without curly bracket . But when u using curly braces like this
For ()
{
}
If you defining any variable in for loop which u did int i=0 its scope will be in inside of brackets u cannot use it outside same things happening in your case your loop is terminated and inside body your i variable showing undefined.
for ()
statement 1;
statement 2 ; here if i won't use brackets then statement 2 will not be part of for loop .
+ 2
/*
Program to print a message without using a semicolon ';' Code (Java Pattern Programs Free)
*/
/*
Program to print 'Hello to Java Programming' without using
semicolon ';'
*/
class ProgWithoutSemiColon {
public static void main(String[] args)
{
if (System.out.printf("Hello to Java Programming")
== null)
{
}
}
}
/*
OUTPUT :
Hello to Java Programming
*/
---------*****---------
(Java Pattern Programs Free)
Get it on Google Play
https://sfet.in/JavaPatternPrograms
+ 1
Jay Matthews error: cannot find symbol
+ 1
Jay Matthews it is working😇 But why is the error coming from the semicolon?
To terminate the semicolon line is🤔
+ 1
Martin Taylor thank you so much
+ 1
General syntax for "for loop" is
for(initialization;condition;increment or decrement)
{
Statements/expressions;
}
We use semicolon to end an expression , do not use it after for loop starting.
+ 1
No need to add semicolon in line 6.
Remove it and run again
+ 1
bro there is " ; "in for loop remove it and everything will be fine , keep learning more 😇✌️