2020.8.30第五十五天

例11.1

 1 import java.util.Scanner;
 2 import java.util.*;
 3 public class cjava {
 4 public static void main(String[]args) {
 5 Student1 s1=new Student1();
 6 s1.get_value();
 7 s1.get_value1();
 8 s1.display();
 9 s1.display_1();
10     }
11 }
12 class Student{
13     private int num;
14     private String name;
15     protected char sex;
16     public void get_value() {
17         Scanner s=new Scanner(System.in);
18         num=s.nextInt();
19         String s2;
20         s2=s.next();
21         sex=s2.charAt(0);
22         Scanner s3=new Scanner(System.in);
23         name=s.nextLine();         
24     }
25     public void display() {
26         System.out.println("num:"+num);
27         System.out.println("name:"+name);
28         System.out.println("sex:"+sex);
29     }
30 }
31 class Student1 extends Student{
32     private int age;
33     private String addr;
34     public void display_1() {
35         System.out.println("age:"+age);
36         System.out.println("address:"+addr);
37     }
38     public void get_value1() {
39         Scanner g=new Scanner(System.in);
40         age=g.nextInt();
41         addr=g.next();    
42     }
43     
44 }

 

 2.遇到的问题:char和string的转换

3.明天继续写例题

posted @ 2020-08-30 23:47  敲敲代代码码  阅读(101)  评论(0编辑  收藏  举报