How to output properly in Java

Hi guys. I’m trying to solve the double string problem (which is obviously trivial). For the sake of not spoiling, I’ve deleted the important bits from my code below. I’m positive I’ve got the correct answer, but still I’m getting a message that says "Your solution from 2012-04-02 17:09:39 to DOUBLE, written in JAVA ran for 1.35 seconds, but produced wrong result. "

Hence, I believe my output is wrong. I’ve tried using print and using println, but neither yield positive results.

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		for (int i = 0; i < n; i++) {
			n = scanner.nextInt();
			/* Some magic happens here*/
			System.out.print(n);
   		}
	}
}

Thanks!

for console o/p in Java, you can use both version. If you use “println”, it’ll automatically print a newline after printing the value of n and if you use “print”, new line character is not printed. For the double string problem, use “println” since we have a number of cases and the answers should be separated by a newline character. If you still get WA, then there might be something wrong with your logic…
good luck…:slight_smile:

1 Like

I still get WA. That’s weird. I did read a bit more and found the Sample problem, which confirmed that System.out.println is indeed the way to go. Thanks!

Inbeforeposting: I just fixed my logic. Was indeed a minor case I had overlooked. Thanks again!