1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)
package a;
import java.util.*;
public class aa {
public static void main(String[] args) {
// TODO Auto-generated method stub
// 1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)
System.out.println("输入年份:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
System.out.println(i + "是一个闰年");
} else {
System.out.println(i + "是一个平年");
}
}
}
2.输入一个4位会员卡号,如果百位数字是3的倍数,就输出是幸运会员,否则就输出不是.
package a;
import java.util.*;
public class aa {
public static void main(String[] args) {
// TODO Auto-generated method stub
//3.已知函数,输入x的值,输出对应的y的值. x + 3 ( x > * 0 ) y = 0 ( x = 0 ) x2 –1 ( x < 0 )
System.out.println("输入一个4位会员卡号:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if (i / 100 % 10 == 3) {
System.out.println("您是幸运会员");
} else {
System.out.println("抱歉,您不是幸运会员");
}
}
}
3.已知函数,输入x的值,输出对应的y的值. x + 3 ( x > * 0 ) y = 0 ( x = 0 ) x2 –1 ( x < 0 )
package a;
import java.util.*;
public class aa {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("输入x:");
Scanner sc = new Scanner(System.in);
int i, sum;
i = sc.nextInt();
if (i > 0) {
sum = i + 3;
} else if (i == 0) {
sum = 0;
} else {
sum = i * i - 1;
}
System.out.println("y的值为:" + sum);
}
}
4.输入三个数,判断能否构成三角形(任意两边之和大于第三边)
package a;
import java.util.*;
public class aa {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("输入三个数字:");
Scanner sc = new Scanner(System.in);
int a, b, c;
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
if (a + b > c && a + c > b && b + c > a) {
System.out.println("这三个数可以组成三角形");
} else {
System.out.println("这三个数不能组成三角形");
}
}
}