21 / 83
Sep 2004

I tried to use the JAVA class: com.braju.beta.format.Format and I am getting a compilation error. I read in a post that was added manually into the classpath...is it true? I was trying to see the diference between this and the standard InputStream reader for the palindrome problem.

regards

Raul

I am afraid the post you are referring to was a little out of date. Indeed, until about a month ago we were using Blackdown JAVA 1.3, and the com.braju.beta.format.Format was available (it worked about twice as slowly as normal IO).

This class was not included in the new Java installation (Sun JAVA 1.5 beta2) for the simple reason, that the newly added standard classes java.util.Scanner and Formatter (as well as the printf method for some other classes) seemed to make it redundant.

Please note that since Sun's JDK 1.5 beta2 differs significantly from 1.5 beta1, and is much closer to the current ReleaseCandidate, you should only use the official documentation of these classes, and not other sources found in the Internet (since they are mostly out of date).

The following is an example of code that will work with the online judge:

import java.util.Scanner;
class Main
{
   public static void main (String [] args)
   {
      /*
         // equivalent C code fragment
         int i;
         float f;
         char s [50];
         printf ("Enter three values -- integer float string: ");
         scanf ("%d %f %s", &i, &f, s);
         printf ("%d %f %s\n", i, f, s);
      */
      System.out.printf ("Enter three values -- " +
                        "integer float string: ");
      Scanner sc = new Scanner (System.in);
      int i = sc.nextInt ();
      float f = sc.nextFloat ();
      String s = sc.nextLine ();
      System.out.printf ("%d %f %s\n", i, f, s);
   }
}

But if you find that these classes do not meet your requirements, please let us know and we will add com.braju.beta.format to the classpath; this is no problem whatsoever.

Glup...well, not a nice increase in performance.

Seems pretty nice, thanks a lot.

Raul

1 year later

SPOJ is not accepting my code? cry

Both solutions mentioned above also give wrong answer! open_mouth

Why does SPOJ says that this code gives wrong answer? Any one who solved this in SPOJ please help.

they say, it will be 1 or 2 digits only. they won't test 421 on the code. so chill smile

1 year later

Hello,
does anybody know why my code is not accepted? I get "runtime error (NZEC)". Earlier when I additionally surrounded the code-line "x = eingabe()" with a try-catch block in order to catch a NumberFormatException from the parseInt()-method i even got "time limit exceeded"... On my machine it works correctly. Here is my code:

import java.util.Iterator;
import java.util.LinkedList;
public class Main
{
	public static void main(String[] args)
	{
		int x;
		LinkedList<Integer> l = new LinkedList<Integer>();
		while(true)
		{
			x = eingabe();
			if(x != 42)
			{
				l.add(new Integer(x));
			}
			else
			{
				break;
			}
		}
		for(Iterator<Integer> i = l.iterator();i.hasNext();)
		{
			System.out.println(i.next());
		}
      System.exit(0);
	}
	static int eingabe()
	{
		String s = "";
		try
		{
			s = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)).readLine();
		}
		catch (java.io.IOException e)
		{
		}
		return java.lang.Integer.parseInt(s);
	}	
}
16 days later

No, the solution is correct, since 420 is an invalid input stuck_out_tongue Read the problem statement.

4 years later

Why my following code get runtime error (NZEC)?
Help!!!
5293653 2011-06-25 11:17:31 Life, the Universe, and Everything runtime error (NZEC)edit run 0.28 177M JAVA

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;
public class Main
{
	private void solve() throws IOException
	{
		for (; ; )
		{
			int N = nextInt();
			if (N == 42)
				break;
			writer.println(N);
		}
	}
	public static void main(String arg[])
	{
		new Main().run();
	}
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	public void run()
	{
		try
		{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}
	int nextInt() throws IOException
	{
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException
	{
		return Double.parseDouble(nextToken());
	}
	String nextToken() throws IOException
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens())
		{
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}
2 months later

I'm getting a NZEC error in code..plz check and reply.
import java.util.*;
public class Main {

public static void main(String args[])
{
	Scanner in=new Scanner(System.in);
	System.out.println("enter the numbers: ");

	int n=0;int i=0;
	int arr[]=new int[10];

	while((n=in.nextInt())!=0)
	{arr[i]=n;	
		i++;

	}
	int j=0;
	while(arr[j]!=42)
	{System.out.println(arr[j]);
	j++;

}


}

}

5 months later

public class Main
{
  public static void main (String[] args) throws java.lang.Exception
  {
     java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
     String s;
     while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
  }
}

I submitted this code and it got accepted... This is not my code though :mrgreen: .... but this code takes any input and print it out as it is.... Then why was it given in the problem that the number should be two digit or one digit integer only...

I made a different code it was taking all input but printing out only those which are integers of one or two digit... I think that is how it should work... But that code was not accepted... it gives wrong output it seems.. open_mouth

Please post the code that you are having difficulty with. (using code tags, see your post that I edited)

The code that you submit does not have to verify that the input follows the specification. The specification determines what sort of input will be given.

You can rest assured that numbers like 122 and 123455730324903242342393276378234123419 and 1.234 will not occur in the input.

6 months later

Why is my following code getting "wrong answer" in SPOJ.
It is working fine in my IDE.
Please HELP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

import java.io.*;
public class Main
{
    /**
 *  This class solves problem 1 classical from SPOJ
 *  @author T
 *  @since 6-Sep-2011
 */
public static void main(String[] args) throws IOException
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	while(true)
	{
		System.out.println("Input:");
		String s = br.readLine();
		if(s.equals("42"))
			break;
		else
			System.out.println("Output:" + s);
	}

}
}

         System.out.println("Input:");

Everything that you output is considered in the result. This alone will give you wrong answer.

2 years later

Anybody knows why I keep getting a NZEC error when I try to submit?

I run it in my terminal as following
javac meaningoflife3.java
java meaningoflife3 test.txt

I think it might be because of the text file?

import java.io.*;
public class meaningoflife3 {
    public static void main(String[] args) throws IOException {
	// TODO Auto-generated method stub
	
	File inFile = null;
	
	if (0 < args.length) {
		inFile = new File(args[0]);	
		}
	try {
		String num;
		
	BufferedReader read = new BufferedReader(new FileReader(inFile));
	while ((num = read.readLine()) != null ){
		if ( num.equals("42"))
			break;
		else
			System.out.println(num);
		}
	}
	catch (IOException e){
		e.printStackTrace();
		}	
	}
	
	
}

Hope you guys can help me identify my error!

amenocal