1055 - Pockets

All about problems in Volume 10. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
vickki
New poster
Posts: 3
Joined: Wed Nov 10, 2010 9:11 am

1055 - Pockets

Post 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 ??
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: First Java prog submission Compilation Error

Post by mf »

Your class should be called Main.
vickki
New poster
Posts: 3
Joined: Wed Nov 10, 2010 9:11 am

Re: First Java prog submission Compilation Error

Post 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:
zobayer
Experienced poster
Posts: 110
Joined: Tue May 06, 2008 2:18 pm
Location: CSE-DU, Bangladesh
Contact:

Re: First Java prog submission Compilation Error

Post 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.
You should not always say what you know, but you should always know what you say.
Post Reply

Return to “Volume 10 (1000-1099)”