public class For02 {
public static void main(String[] args) {
//计算0到100之间的奇数和、偶数和
int oddSum = 0;
int evenSum = 0;
for (int i = 0; i <= 100; i++) {
if (i%2!=0){//奇数
oddSum+=i;//oddSum=oddSum+i
}else{//否则为偶数
evenSum+=i;//evenSum=evenSum+i
}
}
System.out.println("奇数的和:"+oddSum);
System.out.println("偶数的和:"+evenSum);
//用while或for循环输出1-1000之间能被5整除的数,并且每行输出3个
for (int i = 1; i <= 1000; i++) {
if (i%5==0){ //被5整除
System.out.print(i+"\t");//print-不换行 实现空格:\t
}
if (i%(5*3)==0){//每第三个数都能被15整除
System.out.println();//printLn-换行
//或者System.out.print(“\n“);
}
}
//99乘法表
for (int j = 1; j <= 9; j++) {
for (int i = 1; i <= j; i++) {
System.out.print(j+"*"+i+"="+(j*i)+"\t");
}
System.out.println();
}
for (int j = 1; j <= 9; j++) {
for (int i = 1; i <= j; i++) {
System.out.print(j+"*"+i+"="+(j*i)+"\t");//嵌套里面空格不换行
}
System.out.println();//嵌套外换行
}
}
}
标签:练习,String,int,args,循环,public
From: https://www.cnblogs.com/hxl262229/p/18016354