Some things you have to know about Java Support.

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
ithamar
Learning poster
Posts: 56
Joined: Mon May 13, 2002 11:58 pm
Location: Venezuela

Some things you have to know about Java Support.

Post by ithamar » Mon Sep 09, 2002 6:48 am

Hi guys.

This is for those people who are using Java to solve the problems in Valladolid.

I have some time practicing in this site and i have found some things that i think are very useful for begginers.

Here programming in Java we already know is very limitated, classes like TreeSet, BigInteger, Line2D, TreeMap, Arrays are not supported so mucho of the code that i have not to implement in a ACM ICPC contest i have to do it here because of this little problem.

Now this is in process of been solved because Valladolid is going to upgrade the Java Compiler (HUUUUURRRA :D ). So i would not talk about this because this (i expect) problem would become obselete in a few days :lol: .

The main problem that have to be solved is the ReadLn method that is proportionated in the judge page or the test cases that are not coherent with THAT ReadLn proportionated.

Let me explain you the problem with this ReadLn().

Suppose you have a Input file where the End of File is EOF and the input is like this


1
2
3
4
EOF

In this input file your Java Program should work without problem. This is (I hope) the majority of cases here.

But suppose that your File is like this

1
2
3
4EOF

This is not going to work in your Java Program because the last case never is going to be processed with you program. The ReadLn ignore the line with EOF independiently of the content before the EOF. I have seen some problems with a Input file like the last one so be careful and try to upgrade the ReadLn proportionated here to solve this kind of problem.

Another problem that happens, but is rarely seen (at least for me) but i have to be honest and say that i have not put any effort to detect this kind of problems if an input file like this

1
2

3
4
EOF

As you see there is an empty line between the line 2 and three. This is not hard to deal with it. But if the problem does not say anything about empty lines why enlarge your code with this checking. This problems are very annoyng because Pascal, C, C++ eats all the spaces and this is unnoticed but in Java not. So the problemsetters have to be very careful when they are writing the input data.

I write about the last example because if you see that a problem nobody has solved with Java and the algorithm that you consider correct get WA try to deal with empty lines (maybe this is your problem, or i should say the problemsetter problem) .

I would like to know if you find this kind of problems and the problems because i dont want to lose time trying to fix a correct program.

I hope this little advice about some common Java Problems here coud help u.

PD: Be careful with problems 10055 to 10063 some of them have problems of this kind I dont remember which one. But you are alerted.
Those Who Don't Know History are doomed to repeat it

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Post by lnr » Thu Oct 11, 2007 3:48 pm

How can i check EOF in java?
How can i take long long integer in java?
Can anyone help?

Code: Select all

import java.util.*;

public class hasmat
{
	public static void main(String args[])
	{
		long a,b,c;		
		Scanner i=new Scanner(System.in);				
		while(1>0)		
		{
			a=i.nextLong();
			b=i.nextLong();
			
			if(a==0)
				break;
			if(a>b)
				c = a-b;
			else 
				c = b-a;
						
			System.out.println(c);
		}	
	}
}

slxst
New poster
Posts: 23
Joined: Mon Oct 16, 2006 2:18 am

Post by slxst » Sat Oct 13, 2007 7:01 am

Scanner have method .hasNext...() for every .next...() so you can not only check for EOF but also to changes in the input (from numbers to strings for example)

But as far as I know, online-judge doesn't likes Scanner so you can't use it.

Post Reply

Return to “Java”