|
|
back to boardWA 5: help me, this is my code import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class T_1823 { public static final double R = 8.314;
public static void main(String[] args) { Scanner in = new Scanner(System.in); Map<Character, Double> mp = new HashMap<Character, Double>(); for (int i = 1; i <=3; i++) { String s = in.nextLine().trim(); mp.put(s.charAt(0), (double)Integer.parseInt(s.charAt(4)+"")); } if(mp.get('T')!=null) { if(mp.get('T')==0) { System.out.println("error"); return; } } if(mp.get('V')!=null) { if(mp.get('V')==0) { System.out.println("error"); return; } } //System.out.println(mp); if(!mp.containsKey('p')) { double p = mp.get('n')*mp.get('T')*R/mp.get('V'); System.out.print("p = "); if(p==0) System.out.println(0); else System.out.printf("%.6f",p); } if(!mp.containsKey('n')) { double n = mp.get('p')*mp.get('V')/R*mp.get('T'); System.out.print("n = "); if(n==0) System.out.print(0); else System.out.printf("%.6f",n); } if(!mp.containsKey('T')) { if(mp.get('n')==0 && mp.get('p')!=0) { System.out.println("error"); } else { if(mp.get('n')==0 && mp.get('p')==0) { System.out.println("undefined"); } else { double T = mp.get('p')*mp.get('V')/R*mp.get('n'); if(T==0) { System.out.println("error"); } else { System.out.print("T = "); System.out.printf("%.6f",T); } } } } if(!mp.containsKey('V')) { if(mp.get('p')==0 && mp.get('n')!=0) { System.out.println("error"); } else { if(mp.get('n')==0 && mp.get('p')==0) { System.out.println("undefined"); } else { double V = mp.get('n')*R*mp.get('T')/mp.get('p'); if(V==0) { System.out.println("error"); } else { System.out.print("V = "); System.out.printf("%.6f",V); } } } } } } |
|
|