package OrangeWater.struct;
public class Fordemo02 {
public static void main(String[] args) {
//练习:用while或者for循环输出1-1000之间能被5整除的数,并且每行输出3个
//用for
// for (int i = 0; i <= 1000; i++) {
// if (i % 5 == 0) {
// System.out.print(i+"\t");// \t是打一个tab键
// }
// if (i%(5*3)==0){//5*3的意思就是15,对15取余等于0说明加了3次5
// System.out.println();
// }
// }
/* println 输出完会换行
print 输出完不会换行
* */
//用while
int i = 0;
while (i <= 1000){
if (i % 5 == 0) {
System.out.print(i+"\t");// \t是打一个tab键
}
if (i%(5*3)==0){//5*3的意思就是15,对15取余等于0说明加了3次5
System.out.println();
}
i++;
}
}
}
Java中用while或者for循环输出1-1000之间能被5整除的数,并且每行输出3个
最新推荐文章于 2023-10-09 22:01:58 发布