#20378: java參考

#### fdhs10846518 (♞♋低能♋博士♞)

School : 桃園市私立復旦高級中學
ID : 84152
2023-03-22 22:16:15
a866. 6. Product Review Site -- | From: [114.34.47.164] | Post Date : 2020-01-12 11:04

import java.text.DecimalFormat;
import java.util.Scanner;
public class test10584 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int five=0,four=0,three=0,two=0,one=0,sum=0,num=0;
while(scanner.hasNext()) {

int n=scanner.nextInt();
//calculate
if(n!=0) {
num+=1;
if(n==5) {
sum+=5;
five+=1;
}
if(n==4) {
sum+=4;
four+=1;
}
if(n==3) {
sum+=3;
three+=1;
}
if(n==2) {
sum+=2;
two+=1;
}
if(n==1) {
sum+=1;
one+=1;
}
}
else {

//start printing
System.out.print("5 ("+test(five)+") |");
s(five);
System.out.print("4 ("+test(four)+") |");
s(four);
System.out.print("3 ("+test(three)+") |");
s(three);
System.out.print("2 ("+test(two)+") |");
s(two);
System.out.print("1 ("+test(one)+") |");
s(one);

//DecimalFormat
DecimalFormat df=new DecimalFormat("##0.0000");
System.out.println("Average rating: "+df.format((double)sum/num));

//format data
five=four=three=two=one=sum=num=0;
}

}
scanner.close();
}
public static void s(int n) {

//print "="
for(int i=0;i<n;i++) {
System.out.print("=");
}
System.out.println();
}
public static String test(int n) {
if(n<10)return " "+Integer.toString(n);
else return Integer.toString(n);
}
}

ZeroJudge Forum