//1、 判断输入的数能否被3,5,7同时整除 package wf; import java.util.Scanner; public class test1 { @SuppressWarnings("resource") public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("输入一个整数"); int a =scanner.nextInt(); if (a%3==0 && a%5==0 && a%7==0) { System.out.println(a+"可以同时被3 5 7整除"); }else { System.out.println("无法实现"); } } }
2. 输入学生的成绩,输出不同的等级成绩【<60 不及格,60~80:良好,>80:优秀】
package wf; import java.util.Scanner; public class test2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("输入成绩"); int a = scanner.nextInt(); // switch (a/10) { // case 10 : case 9:case 8: // System.out.println("优秀"); // // break; // case 6: case 7: // System.out.println("良好"); // // break; // case 5: case4: // System.out.println("不及格"); // // break; // default: // System.out.println("成绩无效"); // break; // } if(a<=100 && a>80) { System.out.println("优秀"); }else if(a>=60 && a<=80){ System.out.println("良好"); }else if(a>=0 && a<60) { System.out.println("不及格"); }else { System.out.println("数据不合法"); } } }
3.打印九九乘法表
package wf; public class test3 { public static void main(String[] args) { for (int i = 1; i <10; i++) { for (int j = 1; j <= i; j++) { System.out.print(j+"*"+i+"="+i*j+" "); } System.out.println(""); } } }
4.从键盘输入一个百位数,计算并输出个位、十位、百位的数字之和
package wf; import java.util.Scanner; public class test4 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入一个百位数"); int k =sc.nextInt(); int m = k%10; int n = k%100/10; int l = k/100; int a = m+ n +l; System.out.println("和为:" +a); } }
5.用封装的思想定义Product类,包含id,name,price属性
package wf; public class Product { private int id; private String name; private double price; public Product() { super(); // TODO Auto-generated constructor stub } public Product(int id, String name, double price) { super(); this.id = id; this.name = name; this.price = price; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } @Override public String toString() { return "test7 [id=" + id + ", name=" + name + ", price=" + price + "]"; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)