Input data - Compile Error

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
tmnq
New poster
Posts: 5
Joined: Sun Oct 14, 2007 12:24 pm

Input data - Compile Error

Post by tmnq »

Hi all,

Today I tried to submit answers to Columbus weekend Contest #4, but could not pass the "compile error".

Even when I did not include any external libraries. The judges still returned me "Compile error".

Here's my code:

Code: Select all

class Main {
	static String readLine() throws Exception
	{
		char c=' ';
		String str="";
		while (true)
		{
			c=(char) System.in.read();
			if (c=='\n') break;
			str+=c;
		}
		return str;		
	}
	public static void main(String args[]) throws Exception
	{		
		String str=readLine();
		String[] arr= str.split(" ");
		int n= Integer.parseInt(arr[0]);
		double t= Double.parseDouble(arr[1]);
		System.out.printf("Program 1 by team 11568\n");
		while (true)
		{
			str= readLine();
			arr= str.trim().split(" ");
			int a= Integer.parseInt(arr[0]);
			int b= Integer.parseInt(arr[1]);
			int c= a-b;
			if (c<0) c+=n;
			double r= ((float)c-0.5)/(float)(n-1)*t;
			System.out.printf("Chair %3d meets chair %3d, remaining time = %5.1f\n",a,b,r);
		}
	}
}
I have tried Scanner,BufferedInputStream, InputStreamReader and now System.in but always get "Compile Error". Why is it so??

i feel desperate.. Any help will be really appreciated!

Thank u in advance.
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

On the old server (where that contest is) they use Java 1.1.
printf() came in 1.5 (so did String.split()) and I think there was no Double.parseDouble() in 1.1 either.

You should be getting emails after you submit to the old server, you can change that in your profile. It will tell you exactly what the compiler error is.
tmnq
New poster
Posts: 5
Joined: Sun Oct 14, 2007 12:24 pm

Post by tmnq »

Thanks a lot Darko.

I still wonder normally how people input an integer/double/string in this situation? We even need to write a small routine, just for input?
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

Try BufferedReader and StringTokenizer for input parsing. For printing, try the old System.out.print and System.out.println methods.
tmnq
New poster
Posts: 5
Joined: Sun Oct 14, 2007 12:24 pm

Post by tmnq »

Thank you chunyi81.
Post Reply

Return to “Java”