zoukankan      html  css  js  c++  java
  • 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.明天继续写例题

  • 相关阅读:
    Django 前戏
    SQL基本语句
    如何正确安装Mysql
    JQuery
    解疑答惑—解决脱离标准文档流(恶心的浮动)
    事件
    卷基于快照进行恢复
    centos7下Firewall使用详解
    基于镜像卷启动的虚机快照代码分析
    nova卸载volume源码分析
  • 原文地址:https://www.cnblogs.com/Nojava/p/13587343.html
Copyright © 2011-2022 走看看