zoukankan      html  css  js  c++  java
  • 2020.8.9 + 每周周报(5)

    一、今日学习内容    每周周报

      1、求两个数之和的函数,要求使用函数重载,能求整数、长整型、浮点、双精度等数的和。

     1 import java.util.Scanner;
     2 public class Sum {
     3     public static int sum(int a,int b) {
     4         return a+b;
     5     }
     6     public static long sum(long a,long b) {
     7         return a+b;
     8     }
     9     public static float sum(float a,float b) {
    10         return a+b;
    11     }
    12     public static double sum(double a,double b) {
    13         return a+b;
    14     }
    15     public static void main(String[] args) {
    16         Scanner con=new Scanner(System.in);
    17         System.out.print("请输入两个整数:");
    18         int x=con.nextInt();
    19         int y=con.nextInt();
    20         System.out.println("两个整数之和为:"+sum(x,y));
    21         System.out.print("请输入两个长整数:");
    22         long x1=con.nextLong();
    23         long y1=con.nextLong();
    24         System.out.println("两个长整数之和为:"+sum(x1,y1));
    25         System.out.print("请输入两个浮点数:");
    26         float x2=con.nextFloat();
    27         float y2=con.nextFloat();
    28         System.out.println("两个浮点数之和为:"+sum(x2,y2));
    29         System.out.print("请输入两个双精度浮点数:");
    30         double x3=con.nextDouble();
    31         double y3=con.nextDouble();
    32         System.out.println("两个双精度浮点数之和为:"+sum(x3,y3));
    33     }
    34 }

     

       2、完成用户信息录入,要求录入姓名,性别,年龄,家庭住址这四项信息。

     1 import java.util.Scanner;
     2 public class Information {
     3     private String name;
     4     private String sex;
     5     private int age;
     6     private String address;
     7     public static void main(String[] args) {
     8         System.out.print("请输入要登记的人数:");
     9         int n;
    10         Scanner con=new Scanner(System.in);
    11         n=con.nextInt();
    12         Information[] person=new Information[n];
    13         for(int i=0;i<n;i++) {
    14             person[i]=new Information();
    15             System.out.println("请输入第"+(i+1)+"个人的信息(姓名、性别(男、女)、年龄、家庭住址):");
    16             person[i].name=con.next();
    17             person[i].sex=con.next();
    18             person[i].age=con.nextInt();
    19             person[i].address=con.next();
    20         }
    21         System.out.println("姓名"+'	'+"性别"+'	'+"年龄"+'	'+"家庭住址");
    22         for(int i=0;i<n;i++) {
    23             System.out.println(person[i].name+'	'+person[i].sex+'	'+person[i].age+'	'+person[i].address);
    24         }
    25     }
    26 }

      

    二、遇到的问题

       对nextLine()和next()的用法不理解

    三、明日计划

      继续完成习题

    收获:

           在这一周学习了第十二章后半部分的内容,缓冲流、对象的序列化和反序列化、 transient 关键字、打印流等内容,完成了《大道至简》的读后感,工具类的相关例题,完成第十二章的学习后,开始做c++例题用Java实现。

    遇到的问题:

          对第十二章中的相关方法容易混淆,记得不是很清楚,在完成例题时,遇到了很多问题。

    下周计划:

          继续完成c++的例题

  • 相关阅读:
    mac下更改MySQL的默认编码
    pycharm使用gitlab输错密码解决办法
    Django中form组件的is_valid校验机制
    装饰器整理
    粘包
    MySQL常见数据库引擎及对比
    jtag、在线仿真器
    《如何高效学习》-整体性学习策略
    keil5到iar8的使用配置迁移
    Python3学习(1)——初步了解
  • 原文地址:https://www.cnblogs.com/wmdww/p/13463575.html
Copyright © 2011-2022 走看看