1.输入一个数字,为其高,一个符号*,输出该符号组成的平行四边形形状
public static void main(String[] args){ // 1.输入一个数字,为其高,一个符号*,输出该符号组成的平行四边形形状 Scanner sc = new Scanner(System.in); int high = sc.nextInt(); int n = 10; int c ; for(int i = high; i > 0; i--){//高度控制 for (int j = i;j>0;j--){//打印间隔 System.out.print(" "); } if(i != high && i != 1){//非首尾两行打印 System.out.print("*"); for (int wei = 0; wei <9; wei++) { System.out.print(" "); if(wei == 8) System.out.print("*"); } }else {//首尾两行打印 for (int k = 0;k<n;k++) { System.out.print("*"); } } System.out.println(); } }
二、是猴子吃桃问题,每天都吃剩下的一半,再多吃一个,直到第十天剩下一个桃子,问第一天猴子有多少个桃。
public static void main(String[] args) { //二、是猴子吃桃问题,每天都吃剩下的一半,再多吃一个,直到第十天剩下一个桃子,问第一天猴子有多少个桃。 // int n = chiTao(10,1); int m = chiTao(1); System.out.println(m); } private static int chiTao(int time,int i) { if(time == 1) return i; System.out.println(time+" "+i); return chiTao(time-1,2*(i+1)); } private static int chiTao(int time) { if(time == 10) return 1; return (chiTao(time+1)+1)*2; }
三、输入一系列的数字,输出他们正负数个数,输入0截止,要用函数实现
public static void main(String[] args) { // 三、输入一系列的数字,输出他们正负数个数,输入0截止,要用函数实现 Scanner sc = new Scanner(System.in); int[] shuzu = new int[2]; int c = sc.nextInt(); shuzu = count(c, sc); System.out.println(Arrays.toString(shuzu)); } private static int[] count(int c, Scanner sc) { int[] shuzu = new int[2]; while(c != 0){ if(c < 0) { shuzu[0]++; }else { shuzu[1]++; } c = sc.nextInt(); } return shuzu; }
四.是用一个类来记录学生成绩和他班级,里面有几个函数,静态成员和动态成员都有
public static void main(String[] args) { //四、是用一个类来记录学生成绩和他班级, // 里面有几个函数,静态成员和动态成员都有, // 因为题目是回忆版的,题目概述不清,根据之前看过的教材大概自己设置几个函数与静态成员 Student1 student1 = new Student1("zhangsan",99,"5"); System.out.println(student1.teacher_name); System.out.println(student1.toString()); } } class Student1{ private String name; private int score; private String stu_class; public static final String teacher_name = "梨花"; // 常量 public static int a = 89; // 静态成员变量 @Override public String toString() { return "Student1{" + "name='" + name + '\'' + ", score=" + score + ", stu_class='" + stu_class + '\'' + '}'; } public static int getA() { return a; } public static void setA(int a) { Student1.a = a; } public Student1(String name, int score, String stu_class) { this.name = name; this.score = score; this.stu_class = stu_class; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } public String getStu_class() { return stu_class; } public void setStu_class(String stu_class) { this.stu_class = stu_class; } }
五.java重载+,++,=等简单运算符,
不会。