Page 1 of 1

1055 - Pockets

Posted: Wed Nov 10, 2010 9:23 am
by vickki
Hi I am new to uva when ever i submit the java the code (problem no 1055)i get

Code: Select all

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Scan_v3
{
	public static void main(String args[])throws FileNotFoundException
	{
		
	
			Scanner sc = new Scanner(new File(args[0]));
			
			while(sc.hasNextLong())
				{
					
						System.out.println(Math.abs(sc.nextLong()-sc.nextLong()));
				}
			sc.close();
		
	}
}
I get the following error
Main.java:5: class Scan_v2 is public, should be declared in a file named Scan_v2.java
public class Scan_v2
^
1 error

can someone help me ?? And also is this method of Scanning input from file right ??

Re: First Java prog submission Compilation Error

Posted: Wed Nov 10, 2010 1:10 pm
by mf
Your class should be called Main.

Re: First Java prog submission Compilation Error

Posted: Thu Nov 11, 2010 8:54 am
by vickki
Thanks MF this to help others well i also found out that scanning input

Code: Select all

Scanner sc = new Scanner(new File(args[0]))
is not the right way. I got confused by the line in Input section which states
Input is terminated by End of File
". Well for all other info if we do that we run into runtime error if compilation error is solved. well here we have to use

Code: Select all

Scanner sc = new Scanner(System.in)
instead of previous code. As the compiler in UVA works on redirection method of file. i.e.
java Main < input.txt
[/b] rather than
java Main input.txt
. :wink:

Re: First Java prog submission Compilation Error

Posted: Wed Feb 16, 2011 10:46 am
by zobayer
vickki wrote:Thanks MF this to help others well i also found out that scanning input

Code: Select all

Scanner sc = new Scanner(new File(args[0]))
is not the right way. I got confused by the line in Input section which states
Input is terminated by End of File
". Well for all other info if we do that we run into runtime error if compilation error is solved. well here we have to use

Code: Select all

Scanner sc = new Scanner(System.in)
instead of previous code. As the compiler in UVA works on redirection method of file. i.e.
java Main < input.txt
[/b] rather than
java Main input.txt
. :wink:
You should not use Scanner class, it is slow, try to use BufferedReader.