I have just joined SPOJ and this was the first problem I tried. My source code was:
import java.util.*;
public class SOJ1
{
public static void main()
{
Scanner sc = new Scanner(System.in);
boolean input = true;
String n = "";
while(input)
{
System.out.println("Enter a number");
int num = sc.nextInt();
if(num!=42)
n += num+" ";
else
input = false;
}
String numbers[] = n.split(" ");
for(String a: numbers)
System.out.println(a);
}
}
I submitted this with the option of JAVA (Hotspot) when asked for language. A compilation error occured thought this program works fine for me on BLUE J (JAVA IDE I use)
Can someone help me out ?
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while(input.hasNext()) //this code will run untill we break it from the inside
{
int num;
num=input.nextInt();
if(num!=42)
{
System.out.println(num);
}
else
{
break;
}
}
}
}
Suggested Topics
Topic | Category | Replies | Views | Activity |
---|---|---|---|---|
Please Help with Time Limit exceeded in GERGOVIA -Wine trading in Gergovia | JAVA based languages | 4 | 157 | Jul '24 |
Help Regarding TLE in KQUERY | JAVA based languages | 1 | 132 | Jul '24 |