码云地址:https://gitee.com/Helen_en/16012006__liu_chen/tree/master
定义一个有关学生的Student类,内含类成员变量: String name、String sex、int age,所有的变量必须为私有(private)。
能对name,sex,age赋值。
按照格式:类名 [name=, sex=, age=]输出。使用idea自动生成,然后在修改成该输出格式
输入1行name age sex , 调用上面的有参构造函数新建对象。
tom 15 male
Student [name=‘tom‘, sex=‘male‘, age=15]
请补充以下代码,完成输出要求。
1 import java.util.Scanner;
2 public class Main {
3 public static void main(String[] args) {
4 Scanner in = new Scanner(System.in);
5 int a,b,c,d,e;
6 a = in.nextInt();
7 b = in.nextInt();
8 c = in.nextInt();
9 d = in.nextInt();
10 e = in.nextInt();
11 RR rr = new RR();
12 double dd = rr.fun(a,b,c,d,e);
13 System.out.printf("%.2f",dd);
14 }
15 }
16 class RR{
17
18
19 }
在一行中给出5个不超过1000的正整数。
输出5个整数的平均值,保留小数点后两位
1 2 3 4 5
3.00
程序填空题。根据题目要求完善下面的代码。请提交完整代码。 一个木块如果高度比宽度大,我们说它是竖着放的,否则我们说它是平放的。 读入一个木块的高度和宽度。如果它是平放的,则输出A,否则输出B。
1 import java.util.Scanner;
2 public class Main{
3 public static void main(String[] args){
4 Scanner in = new Scanner(System.in);
5 int height, width;
6 char status;
7 height = in.nextInt();
8 width = in.nextInt();
9 Board board = new Board(height, width);
10 status = board.getStatus();
11 System.out.print(status);
12 }
13 }
14 class Board{
15 int height, width;
16 public Board(int height, int width){
17 this.height = height;
18 this.width = width;
19 }
20 public char getStatus(){
21 if(height<=width){
22 return status(1);
23 }else{
24 return status(1.0);
25 }
26 }
27 public char status(double rate){
28
29 }
30 public char status(int rate){
31
32 }
33 }
输入格式:
输入在一行中给出2个绝对值不超过1000的正整数A和B。
输出格式:
在一行中输出一个字符A或者B。
50 50
:A
程序改错题。以下代码存在错误,请修改后提交。
1 public class Main {
2 public static void main(String[] args) {
3 Animal animal = new Dog();
4 animal.shout();
5 animal.run();
6 }
7 }
8
9 class Animal {
10 void shout() {
11 System.out.println("animal shout!");
12 }
13 }
14
15 class Dog extends Animal {
16 void shout() {
17 super.shout();
18 System.out.println("wangwang……");
19 }
20
21 void run() {
22 System.out.println("Dog is running");
23 }
24 }
animal shout!
wangwang……
Dog is running
原文:https://www.cnblogs.com/nbvc/p/9781246.html