其他分享
首页 > 其他分享> > 牛客网||BC11 学生基本信息输入输出

牛客网||BC11 学生基本信息输入输出

作者:互联网

牛客网||BC11 学生基本信息输入输出

最后通过的代码:

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner quan=new Scanner(System.in);
        String[] date=quan.nextLine().split("[;,]");
        int xuehao=Integer.parseInt(date[0]);
        double score1=Double.parseDouble(date[1]);
        double score2=Double.parseDouble(date[2]);
        double score3=Double.parseDouble(date[3]);
        System.out.println("The each subject score of  No. "+xuehao+" is "+String.format("%.2f",score1)+", "+String.format("%.2f",score2)+", "+String.format("%.2f",score3)+".");
    }
}

我的问题:
在这里插入图片描述
String[ ] date=quan.nextLine().split(;,);
在这里插入图片描述没有注意小数点问题
在这里插入图片描述

我的记录:

  1. split 函数可以用于按指定字符(串)去分割某个字符串,结果以字符串数组形式返回;
  2. String.format( )它通过格式操作使任意类型的数据转换成一个字符串。
    例如:String.format("%.2f",score1);

标签:%.,String,format,输入输出,BC11,牛客,2f,score1,date
来源: https://blog.csdn.net/zhurouwanzi/article/details/119908923