题目:
输入:
3
0 101 20
2 30
输入第一个数表示有三行,期望技术为每行两个数相乘的结果相加,然后除以100,保留三位小数。
输出:
0.800
java实现代码;
package com.mytest.test0322;
import java.text.DecimalFormat;
import java.util.Scanner;
public class my360a {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = Integer.parseInt(in.nextLine());
float ex=0;
String[] str=new String[n];
for(int i=0;i<n;i++){
str[i]=in.nextLine();
}
String[] s=new String[2];
for (String string : str) {
s=string.split(" ");
ex=ex+Integer.parseInt(s[0])*Integer.parseInt(s[1]);
}
float result=ex/100;
DecimalFormat fnum = new DecimalFormat("##0.000");
String dd=fnum.format(result);
System.out.println(dd);
}
}
}