Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

JAVA 和C 这么大差别?

Posted by sun19890208 at 2013-03-10 23:24:08 on Problem 1004
#include<stdio.h>
#include<stdlib.h>
int main(){
 float m,sum;
 sum=0;
 for(int i=0;i<12;i++){
  scanf("%f",&m);
  sum=sum+m;
 }
 sum=sum/12;
 printf("$%.2f",sum);
 return 0;
}

java的复制版  Eclipse上完全没问题 Float double 都能满足要求精度。
为啥C 一下就AC  JAVA总是WA 我了个擦擦
import java.text.DecimalFormat;
import java.util.Scanner;

public class M1004 {
	public static void main(String[] args) {
		float m,sum;
		 sum=0;
		 Scanner sc = new Scanner(System.in);
		 for(int i=0;i<12;i++){
		  m = sc.nextFloat();
		  sum=sum+m;
		 }
		 sum=sum/12;
		 DecimalFormat df = new DecimalFormat("#.##");
		 System.out.println(df.format(sum));
	}
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator