|
|
back to boardDiscussion of Problem 1020. RopeHelp JAVA Program For some reason it wont read the input correctly, my arrays dont contain the right coordinates. Can anyone tell me why? import java.util.*; import java.io.*; public class rope { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt(); int r = in.nextInt();
double[] x = new double[n]; double[] y = new double[n];
double ans = 0.0; ans += 2*Math.PI*r;
for (int i=0; i<n; i++) { x[i]=in.nextDouble(); y[i]=in.nextDouble(); }
for (int i=0; i<n; i++) { ans+= Math.sqrt(Math.pow((x[i]-x[i==0 ? n- 1 : i-1]),2)+Math.pow((y[i]-y[i==0 ? n- 1:i-1]),2)); }
out.println(ans); out.flush(); } } Re: Help JAVA Program r is real. Double r = in.nextDouble(); Re: Help JAVA Program Code ================================================================= import java.util.*; import java.io.*; public class t1020 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);
int N = in.nextInt(); Double R = in.nextDouble();
Double[] x = new Double[N]; Double[] y = new Double[N];
double len = 2 * Math.PI * R;
for(int i = 0; i < N; i ++) { x[i] = in.nextDouble(); y[i] = in.nextDouble(); }
for(int i = 0; i < N - 1; i ++) len += Math.sqrt(Math.pow((x[i] - x[i == 0 ? N - 1 : i - 1]), 2) + Math.pow((y[i] - y[i == 0 ? N - 1 : i - 1]), 2));
out.println(len); out.flush(); } } ================================================================ Write: ================================================================ 4 1.0 Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextDouble(Unknown Source) at t1020.main(t1020.java:12) ================================================================= Why I can not read 1.0?! 4 1 -- Read correctly!!! Re: Help JAVA Program in.useLocale(Locale.US); |
|
|