2013年12月8日星期日

Loop error

public class text {
public static void main (String sunying) {
int num = 5;
for (int i = 1; i <= 100; i + +) {
if (i% 3 == 0) {System.out.println (i); num + +;}; if (num == 5) {break;};
}
}
}



------ Solution ------------------------------------ --------

            public static void main (String args[]){
int num=5;
for(int i=1;i<=100;i++){
if(i%3==0) { //首次進入循環,i=1;i%3 != 0; num =5;
System.out.println(i);
num++;
};
if(num==5) { // 直接跳出循環
break;
};
}


------ For reference only ---------------------- -----------------
javac not being given ,
a JAVA on the error . Strange.
------ For reference only -------------------------------------- -
public static void main (String sunying) wrong, missing the main function entry
public static void main (String args [])
------ For reference only ----------------- ----------------------
plus [ ] executed , how or what do not show it . Where there is written wrong?
------ For reference only -------------------------------------- -
Thank you. Understand.

没有评论:

发表评论