码迷,mamicode.com
首页 > 编程语言 > 详细

java之控制语句例

时间:2020-05-22 21:09:52      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:system   合数   ring   break   sum   str   +=   sys   dial   

不是精简的

/*判断是否闰年

求和

阶乘

合数

素数

菱形

倒正数*/

import javax.swing.JOptionPane;

public class Zuo {

public static void main(String[] args) {
// String a=JOptionPane.showInputDialog("请输入年份:");

// int b=Integer.parseInt(a);
int b = 3231;
if (b % 100 == 0) {
if (b % 400 == 0) {
System.out.println("是闰年");
} else {
System.out.println("不是闰年");
}

} else if (b % 4 == 0) {
System.out.println("是闰年");
} else {
System.out.println("不是闰年");
}
if (b % 4 == 0 && b % 100 != 0 || b % 400 == 0) {
System.out.println("是闰年");
} else {
System.out.println("不是闰年");
}
int sum = 0;
for (int i = 1; i <= 100; i++) {
sum += i;
}
System.out.println("1+2+...+100=" + sum);

int a = 9, sum1 = 1;String r="";
for (int i = 1; i <= a; i++) {
sum1 *= i;
}
System.out.println("a!=" + sum1);

int he = 0, He, ji = 0;
for (int i = 1; i <= 1000; i++) {

for (int j = 2; j < i; j++) {
if (i % j == 0) {
he = i;
break;

}
}
if (he != 0) {
He = he + 1;
if (He - 1 == i) {
r+= he+" ";
ji += 1;
}
}
continue;
}
System.out.println(ji+"个");
System.out.println("合数:"+r);

int su = 2, o, geshu = 0;
String l = "";
for (int i = 1; i <= 1000; i++) {
o = 0;
for (int j = 2; j < i; j++) {

int w = i % j;
if (w == 0) {
o += 1;
break;
}
}
if (o == 0) {
su = i;
}
// Su = su + 1;
// if (Su - 1 == i && i != 1) {
if (su == i && i != 1) {
l += su + " ";
geshu += 1;
}
}
System.out.println(geshu+"个");
System.out.println("素数:" + l);

}
}

public class Fx {

public static void main(String[] args) {
for (int i = 0; i <= 10; i += 2) {
System.out.println();
int num = 10;
for (int j = 0; j <= num - i; j++) {

System.out.print(" ");
num -= 1;
}

for (int j = 0; j <= i; j++) {

if (j == i || j == 0) {

System.out.print("*");
} else {
System.out.print(" ");
}

}

}
for (int i = 10; i >= 0; i -= 2) {
System.out.println();
int num = 10;
for (int j = 0; j <= num - i; j++) {
System.out.print(" ");
num -= 1;
}
for (int j = 0; j <= i; j++) {
if (j == i || j == 0) {

System.out.print("*");
} else {
System.out.print(" ");
}

}

}
System.out.println();
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {

for (int j = 0; j <= 10; j++) {
System.out.print(" " + j);
}
} else {
for (int j = 10; j >= 1; j--) {
System.out.print(" " + j);
}
}
System.out.println();

}

}

}

java之控制语句例

标签:system   合数   ring   break   sum   str   +=   sys   dial   

原文地址:https://www.cnblogs.com/jinjinqiao/p/12939684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!