用三种循环语句来实现输出10~50之间的3的倍数,并规定一行输出5个数。
程序员文章站
2022-03-13 12:27:17
...
用三种循环语句来实现输出10~50之间的3的倍数,并规定一行输出5个数。
package Test;
/**
* @Author liguo
* @Description3. 用三种循环语句来实现输出10~50之间的3的倍数,并规定一行输出5个数。
* @Data 2018-03-29 18:44
*/
public class Test3 {
public static void main(String[] args) {
int count = 0;
for (int i = 10; i <= 50; i++) {
if (i % 3 == 0) {
count++;
System.out.print( i + " " );
}
if (count % 5 == 0)
System.out.println();
}
// int i = 10;
// int count = 0;
// do {
// if (i % 3 == 0) {
// System.out.print( i + " " );
// count++;
// }
// if (count % 5 == 0)
// System.out.println();
// i++;
// } while (i <= 50 && i >= 10);
//
// int i = 10;
// int count = 0;
// while (i <= 50 && i >= 10) {
// if (i % 3 == 0) {
// System.out.print( i + " " );
// count++;
// }
// if (count % 5 == 0)
// System.out.println();
// i++;
// }
}
}