整数逆序输出, 例如输入一个整数12345,输出5 4 3 2 1
/*13. 整数逆序输出, 例如输入一个整数12345,输出5 4 3 2 1
12345 / 10 % 10 == 5;
12345 / 10 / 10 % 10 == 4;
12345 / 10 / 10 / 10 % 10 == 3;
*/
import java.util.Scanner;
class HomeWork1 {
public static void main(String[] args) {
int i = 0;
int yu = 0;
Scanner sc = new Scanner(System.in);
i = sc.nextInt();
while (i > 0) {
yu = i % 10;
i = i / 10;
System.out.println(yu);
}
}
}
java用户输入一个年份,判断这个年份是不是一个闰年。
import java.util.Scanner;
class Test {
public static void main(String[] args) {
int year = 0;
Scanner sc = new Scanner(System.in);
year = sc.nextInt();
boolean ret = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
if (ret) {
System.out.println("是闰年!");
} else {
System.out.println("很遗憾,不是闰年哦!");
}
}
}
打印输出 逢7过!!!
class Test {
public static void main(String[] args){
for (int num = 0 ; num <= 100 ;num ++) {
if (num % 7 == 0 || num / 10 == 7 || num % 10 == 7) {
System.out.println("过");
}else {
System.out.println(num);
}
}
}
}