for循环 学习记录
class ForTest
{
public static void main(String [] args)
{
for (int i = 1;i<=5 ;i++ )
{
System.out.println("Hello World");
}
int num = 1;
for (System.out.print('a');num<=3 ;System.out.print('c'),num++ )
{
System.out.print('b');
}
System.out.println();
int sum = 0;
int count = 0;
for (int i = 1; i<=100 ;i++ )
{
if (i % 2 == 0)
{
System.out.println(i);
sum += i;
count++;
}
}
System.out.println("总和为" + sum);
System.out.println("偶数的个数为" + count);
}
}
class ForTest1
{
public static void main(String [] args)
{
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();
}
}
}