package czlclass.First.operator; public class For1 { public static void main(String[] args) { int m =0; int n =0; for (int i = 0; i < 100; i++) { if (i%2!=0){ //判断奇数 m+=i; //m+i }else{ //偶数 n+=i; } } System.out.println("奇数的和为:"+m); System.out.println("偶数的和为:"+n); } }
====================================================================
1000以内,5的倍数之和,三个一行
package czlclass.First.operator; public class For2 { public static void main(String[] args) { for (int i = 0; i < 1000; i++) { if (i%5==0){ System.out.print(i+"\t"); } if (i%(3*5)==0){ //每行三个,换行 System.out.println("\n"); } } } }