for 循环联系题
计算0-50的奇数和偶数的和
package com.beijing.xiaowen.scanner;
public class Test01 {
public static void main(String[] args) {
//计算0-50的奇数和偶数的和
int a = 0;
int b = 0;
for (int i = 0; i <= 50; i++) {
if (i % 2 == 0 ){
a+=i;
}else {
b+=i;
}
}
System.out.println(a);
System.out.println(b);
}
}
打印0-100,能被3整除的数字,每行打印3个
package com.beijing.xiaowen.scanner;
public class Test02 {
public static void main(String[] args) {
//打印0-100,能被3整除的数字,每行打印3个
for (int i = 1; i < 100; i++) {
if (i%3==0){
System.out.print(i+"\t");
}
if (i%9==0) {
System.out.println();
}
}
}
}
打印九九乘法表
package com.beijing.xiaowen.scanner;
import java.util.ArrayList;
public class Test03 {
public static void main(String[] args) {
//打印九九乘法表
for (int i = 1; i < 10; i++) {
for (int i1 = 1; i1 <= i; i1++) {
System.out.print(i1+"*"+i+"="+i*i1+"\t");
}
System.out.println();
}
}
}
打印三角形 5行
package com.beijing.xiaowen.scanner;
public class Test04 {
public static void main(String[] args) {
//打印三角形 5行
for (int i = 1; i <= 5; i++) {
for (int i1 = 5; i1 >i; i1--) {
System.out.print(" ");
}
for (int i1 = 0; i1 < i; i1++) {
System.out.print("*");
}
for (int i1 = 1; i1 < i; i1++) {
System.out.print("*");
}
System.out.println();
}
}
}
标签:联系,int,打印,System,i1,循环,public,out
From: https://www.cnblogs.com/always0708/p/16808330.html