java for loop

class TestFor{
public static void main(String [] args){
for(int i = 1; i <= 100; i++){
System.out.println(i);

}

for (int i=1; i<=150 ; i++){
System.out.print(i);

if(i%3 == 0){
System.out.print("foo");
}
if (i%5 == 0){
System.out.print ("biz");

}
if (i%7 == 0){
System.out.print("baz");

}
System.out.println();

}

//1. Find all even numbers within 1-200 and
int sum=0;
for(int i =1;i <=200;i++){
if(i%2==0)
sum +=i;
}
System.out.println(sum);
//2. print All prime numbers within 1-200 (integers with and only two positive divisors)
//How to judge whether a number is a prime number: an integer that can only be divided by 1 and itself (1 is not a prime number)

for(int n=2;n<=200;n++){
//int n=121247;
boolean flag =true;
for (int i=2;i<n;i++){
if(n%i==0){
flag=false;
//System.out.println(i);
break;
}
}
if(flag){

System.out.println("-->"+ n);
}
}
}


}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325219821&siteId=291194637