标签:ted next load todo efault default main none pre
1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)
package ktlx; import java.util.Scanner; public class Ktlx1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个年份:"); int year=input.nextInt(); if(year%4==0&&year%100!=0||year%400==0){ System.out.println(year+"年是闰年"); } else{ System.out.println(year+"年不是闰年"); }
2.输入一个4位会员卡号,如果百位数字是随机数,就输出是幸运会员,否则就输出不是.
package ktlx; import java.util.Random; import java.util.Scanner; public class Ktlx2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入四位会员卡号"); int vip=input.nextInt(); Random r=new Random(); int b=r.nextInt(10); System.out.println("随机数是"+b); if(b==vip/100%10){ System.out.println("恭喜成为幸运会员!"); } else{ System.out.println("不是幸运会员,感谢参与!"); }
3.已知函数,输入x的值,输出对应的y的值.
x + 3 ( x > 0 ) y = 0 ( x = 0 ) x*2 –1 ( x < 0 ) package ktlx; import java.util.Scanner; public class Ktlx3 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入X的值:"); double x=input.nextDouble(); if(x>0){ System.out.println("y="+(x+3)); }else if(x==0){ System.out.println("y=0"); }else{ System.out.println("y="+(x*2-1)); } }
4.输入三个数,判断能否构成三角形(任意两边之和大于第三边)
package ktlx; import java.util.Scanner; public class Ktlx4 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入三角形的三边"); int a=input.nextInt(); int b=input.nextInt(); int c=input.nextInt(); if(a+b>c&&a+c>b&&b+c>a){ System.out.println("这三边能构成三角形"); }else{ System.out.println("这三边不能构成三角形"); } }
1:输入年份月份,输出该月的天数
package Homework; import java.util.Scanner; public class Test1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int day; Scanner input=new Scanner(System.in); System.out.println("请输入年份、月份:"); int year=input.nextInt(); int month=input.nextInt(); switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: day=31; System.out.println("天数="+day); break; case 4: case 6: case 9: case 11: day=30; System.out.println("天数="+day); break; case 2: if(year%4==0&&year%100!=0||year%400==0){ day=29; System.out.println("天数="+day); }else{ day=28; System.out.println("天数="+day); } break; default: System.out.println("月份输入错误"); } }
2、给定一个成绩a,使用switch结构求出a的等级。
A:90-100,B:80-89,C:70-79,D:60-69,E:0~59 package home; import java.util.Scanner; public class Work1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int b; Scanner input=new Scanner(System.in); System.out.println("请输入成绩:"); double a=input.nextDouble(); b=(int)a/10; switch(b){ case 10: case 9: System.out.println("该成绩的等级为A"); break; case 8: System.out.println("该成绩的等级为B"); break; case 7: System.out.println("该成绩的等级为C"); break; case 6: System.out.println("该成绩的等级为D"); break; case 5: case 4: case 3: case 2: case 1: case 0: System.out.println("该成绩的等级为E"); break; default: System.out.println("输入成绩有误,请重新输入!"); } }
3、输入一个数字,判断是一个奇数还是偶数
package home; import java.util.Scanner; public class Work2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个数以判断其奇偶性:"); int sum=input.nextInt(); if(sum==0){ System.out.println("0既不是奇数也不是偶数"); }else if(sum!=0&&sum%2==0){ System.out.println("此数为偶数"); }else { System.out.println("此数为奇数");
4、编写程序, 判断一个变量x的值,如果是1, 输出x=1,如果是5,输出x=5,如果是 10,输出 x=10,除了以上几个值,都输出x=none。
package home; import java.util.Scanner; public class Work3 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个变量数值:"); double x=input.nextDouble(); if(x==1){ System.out.println("x=1"); }else if(x==5){ System.out.println("x=5"); }else if(x==10){ System.out.println("x=10"); }else{ System.out.println("x=none"); } }
5、判断一个数字是否能被5和6同时整除(打印能被5和6整除),或只能被5整除(打印能被5整除 ),或只能被6整除,(打印能被6整除),不能被5或6整除,(打印不能被5或6整除)
package home; import java.util.Scanner; public class Work4 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个数字:"); double sum=input.nextDouble(); if(sum%5==0&&sum%6==0){ System.out.println("该数能被5和6整除"); }else if(sum%5==0){ System.out.println("该数能被5整除"); }else if(sum%6==0){ System.out.println("该数能被6整除"); }else{ System.out.println("该数不能被5或6整除"); } }
标签:ted next load todo efault default main none pre
原文地址:https://www.cnblogs.com/vggh/p/14588238.html