1 / 4
Dec 2011

this is my first program but always i get NZEC frowning

this is the code :

public class Main{
	public static String egypt(int x, int y ,int z){
		if(x>0 && y>0 && z>0 && x<30000 && y<30000 && z<30000){
			if(Math.pow(x,2)+Math.pow(y,2)==Math.pow(z,2)){
				return "right";
			}
			else{
				return "wrong";
			}
		}
		else{
			return "wrong";
		}
	}
	public static void main (String[] args) throws java.lang.Exception{
		java.io.BufferedReader sc = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
		String r = sc.readLine();
		while(!r.equals("0 0 0")){
			int x = Integer.parseInt(r.substring(0,r.indexOf(" ")));
			r = r.substring(r.indexOf(" ")+1);
			int y = Integer.parseInt(r.substring(0,r.indexOf(" ")));
			r = r.substring(r.indexOf(" ")+1);
			int z = Integer.parseInt(r);
			System.out.println (egypt(x,y,z));
			r= sc.readLine();
		}
	}
}
  • created

    Dec '11
  • last reply

    Dec '11
  • 3

    replies

  • 307

    views

  • 2

    users

Your program assumes that there is exactly one space between numbers

If this is not the case, then you get a java.lang.NumberFormatException.

You do not post the problem name and number, so I cannot check. It is probably the case that the problem specification doe not state that the numbers are seperated by exactly one space.

the is Egypt problem
and in the rules the program stop win read 0 0 0 see it

Yes, but I was not talking about the final line. Your program assumes that there is exactly one space between numbers for all input.

If this is not the case, then you get a java.lang.NumberFormatException.

For your test, enter multiple spaces between numbers. This will result in an exception.

Suggested Topics

Want to read more? Browse other topics in JAVA based languages or view latest topics.