Issue
Why this code doesn't works on Eclipse but works fine on some other IDEs. The problem I am facing with the code is that Eclipse doesn't call the last loop while I tried running the same snippet on some online Java compilers it runs okay and call all the loops.
I'm using:
Eclipse version: Oxygen 3
Java version: openjdk version "1.8.0_151"
System: Ubuntu 16.04 LTS.
Input Data:
4
5 3
0 0 0 0 0
6 5
0 0 0 1 1 1
6 3
0 0 1 1 1 0
3 1
0 1 0
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int loops = sc.nextInt();
for (int i = 0; i < loops; i++) {
int noOfElements = sc.nextInt();
int leapValue = sc.nextInt();
System.out.println("loop get called" + i);
int array[] = new int[noOfElements];
for (int j = 0; j < noOfElements; j++) {
int u = sc.nextInt();
System.out.println(u);
array[j] = u;
System.out.println("Imcalled");
}
}
}
Ouput
loop get called0
0
Imcalled
0
Imcalled
0
Imcalled
0
Imcalled
0
Imcalled
loop get called1
0
Imcalled
0
Imcalled
0
Imcalled
1
Imcalled
1
Imcalled
1
Imcalled
loop get called2
0
Imcalled
0
Imcalled
1
Imcalled
1
Imcalled
1
Imcalled
0
Imcalled
loop get called3
Solution
Your problem is not with your code or not even with eclipse. Eclipse's Consul is not design for reading any input value rather it has been design for standard output
and standard error
messages. Even though it can read from the consul but that is not efficiently design . Better run you program from command line. First make jar file (right click on your project->export->jar) and call like java -jar /path/to/your.jar
Answered By - Abhijit Pritam Dutta