Life, the Universe, and Everything

Hey,

I’m a novice programmer and recently decided to join CodeChef to expand my knowledge. I’m attempting the first easy question called, ‘Life, the Universe, and Everything’ and I’ve written some code and was wondering if you guys could help me resolve the problems within.

import java.io.*;
import java.util.*;

public class Main {
public static void main (String [] args) {
	int i;

	Scanner kbReader = new Scanner(System.in);

	System.out.println("Please input an integer: ");
	int fortytwo = kbReader.nextInt();

	for (i = 0; i > 10; i++) {
		if (fortytwo == 42) {
			i = 10;
		} else {
			System.out.println(fortytwo);
			System.out.println("Please input an integer: ");
			fortytwo = kbReader.nextInt();

		}
		}

	}
}

Thanks again,

Dillon

Hi, please tell me, where that idea of printing "Please input an integer: " comes from, so many users is doing that…

Please read FAQ to understand better why you cannot do that :wink:

4 Likes

I was under the impression that due to the next line ‘int fortytwo = kbReader.nextInt();’, the user input would be stored in the variable fortytwo.

@dillonpatel >> That’s fine but unfortunately ONLINE_JUDGE doesn’t understand English so he won’t read "Please input an integer: ", he will simply test your code with some predefined input and check if it produces desired output or not. No need to ask him to input. Just do that in your code.

//