依次输入一个学生的学号,以及3科(C语言,数学,英语)成绩,在屏幕上输出该学生的学号,3科成绩(注:输出成绩时需进行四舍五入且保留2位小数)。
数据范围:学号满足 ,各科成绩使用百分制,且不可能出现负数
学号以及3科成绩,学号和成绩之间用英文分号隔开,成绩之间用英文逗号隔开。
学号,3科成绩,输出格式详见输出样例。
17140216;80.845,90.55,100.00
The each subject score of No. 17140216 is 80.85, 90.55, 100.00.
123456;93.33,99.99,81.20
The each subject score of No. 123456 is 93.33, 99.99, 81.20.
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String info = in.nextLine(); String num = info.split(";")[0]; String [] scores = info.split(";")[1].split(","); for(int i = 0; i < scores.length;i++){ scores[i] = String.format("%.2f", Double.parseDouble(scores[i])); } System.out.println("The each subject score of No. "+num+" is "+scores[0]+", "+scores[1]+", "+scores[2]+"."); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str1 = in.nextLine(); String[] arr =str1.split(";|,"); double[] douarr = new double[3]; for(int i=0;i<douarr.length;i++){ douarr[i]=Double.parseDouble(arr[i+1]); } String s = String.format("The each subject score of No. %s is %.2f, %.2f, %.2f.",arr[0],douarr[0],douarr[1],douarr[2]); System.out.println(s); } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.nextLine(); String[] arr=s.split(";"); String[] scores=arr[1].split(","); Double[] scores1=new Double[3]; for(int i=0;i<scores.length;i++) scores1[i]=Double.parseDouble(scores[i]); System.out.printf("The each subject score of No. %s is %.2f, %.2f, %.2f.",arr[0],scores1[0],scores1[1],scores1[2]); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.nextLine(); String[] strArr = str.split(";"); String[] scores = strArr[1].split(","); Integer stdNO = Integer.parseInt(strArr[0]); Double C_language_score = Double.parseDouble(scores[0]); Double Math_score = Double.parseDouble(scores[1]); Double English_score = Double.parseDouble(scores[2]); System.out.println("The each subject score of No. " + stdNO + " is " + String.format("%.2f",C_language_score) + ", " + String.format("%.2f",Math_score) + ", " + String.format("%.2f",English_score) + "."); } }
import java.util.*; import java.text.DecimalFormat; import java.math.BigDecimal; import java.math.RoundingMode; public class Main { public static void main(String [] args) { Scanner input=new Scanner(System.in); while(input.hasNextLine()) { String score=input.nextLine(); String [] numbers=score.split(";"); String [] arr=numbers[1].split(","); System.out.print("The each subject score of No. "+numbers[0]+" is "); for(int i=0;i<arr.length;i++) { BigDecimal bigDecimal = new BigDecimal(arr[i]); DecimalFormat decimalFormat = new DecimalFormat("0.00"); decimalFormat.setRoundingMode(RoundingMode.HALF_UP); if(i==arr.length-1){ System.out.print(decimalFormat.format(bigDecimal)+"."); } else { System.out.print(decimalFormat.format(bigDecimal)+", "); } } System.out.println(); } } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sin = new Scanner(System.in); // 输入是一个连续的字符串,使用我们要把输入的字符串按照分隔符写到字符串数组里面 String[] data = sin.nextLine().split("[;,]"); // 把字符串数组里面的数据转换成对应的数据 long id = Integer.parseInt(data[0]); double score1 = Double.parseDouble(data[1]); double score2 = Double.parseDouble(data[2]); double score3 = Double.parseDouble(data[3]); System.out.println("The each subject score of No. " + id + " is " + String.format("%.2f",score1) + ", " + String.format("%.2f",score2) + ", " + String.format("%.2f",score3) + "."); } }
import java.math.BigDecimal; import java.util.ArrayList; import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); //向student[]中假如学生的no.因为只有no是被";"隔开的 String[] student = in.nextLine().split(";"); //剩下学生的成绩存储到scores[]数组中,因为成绩使用","隔开的 String[] scores = student[1].split(","); //用nums数组存储四舍五入之后score的值 ArrayList<BigDecimal> nums = new ArrayList<>(); for (String s : scores){ BigDecimal num = new BigDecimal(s); //用setScale方法来处理小数部分 num = num.setScale(2,BigDecimal.ROUND_HALF_UP); nums.add(num); } System.out.println("The each subject score of No. "+student[0]+" is "+nums.get(0)+", "+nums.get(1)+", "+nums.get(2)+"."); } }
import java.util.Scanner; import java.util.ArrayList; import java.math.BigDecimal; public class Main{ public static void main(String[] args){ Scanner s = new Scanner(System.in); String[] msg = s.next().split(";"); String[] scores = msg[1].split(","); ArrayList newScores = new ArrayList(); for(String item : scores){ BigDecimal num = new BigDecimal(item); //用BigDecimal的方法处理小数部分 num = num.setScale(2,BigDecimal.ROUND_HALF_UP); newScores.add(num); } System.out.println("The each subject score of No. " + msg[0] + " is " + newScores.get(0) + ", " + newScores.get(1) + ", " + newScores.get(2) + "."); } }
import java.util.Scanner; public class Main{ public static void main(String argn []){ Scanner input =new Scanner(System.in); String inputStr=input.nextLine(); String []strArr1=inputStr.split(";"); String num=strArr1[0]; String[]scoreArr= strArr1[1].split(","); System.out.print("The each subject score of No. "+num+" is "); for(int i=0;i<scoreArr.length;i++){ double dou=Double.parseDouble(scoreArr[i]); System.out.printf("%.2f",dou); if(i==scoreArr.length-1){ System.out.print("."); }else{ System.out.print(", "); } } } }
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); String score = sc.nextLine(); String[] s = score.split(";"); String[] s2 = s[1].split(","); System.out.printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", Integer.valueOf(s[0]), Float.valueOf(s2[0]), Float.valueOf(s2[1]), Float.valueOf(s2[2])); } }
//承认自己不熟悉格式化
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { String str=sc.next(); String [] arr1=str.split(";"); String noStr=arr1[0];//学号 String scoreStr=arr1[1];//三科成绩 String [] arr2=scoreStr.split(","); double c=Double.parseDouble(arr2[0]);//C语言的成绩 double shu=Double.parseDouble(arr2[1]);//数学的成绩 double ying=Double.parseDouble(arr2[2]);//英语的成绩 System.out.print("The each subject score of No. "); System.out.print(noStr); System.out.print(" is "); System.out.printf("%.2f",c); System.out.print(", "); System.out.printf("%.2f",shu); System.out.print(", "); System.out.printf("%.2f",ying); System.out.print("."); System.out.println(); } }