I'm trying to print the value of z as output but My code doesn't finish execution..it reaches the line "here" but never reachs the last line "z is ".
i'm guessing s = sc.nextInt(); is the problem.
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int x = 0;
int y = 0;
int z = 0;
int u = 0;
int n = sc.nextInt();
int s = sc.nextInt();
while(sc.hasNextInt()) {
if(s != -1){
y = s;
if(sc.hasNextInt()){
s = sc.nextInt();
}
}
while(s == -1){
x++;
System.out.println("s is "+s);
z = Math.abs(y - x) + u;
System.out.println("s is "+s);
System.out.println("x is " + x+ " y is "+ y+" z is "+z);
if(sc.hasNextInt()){
s = sc.nextInt();
System.out.println("s33 is "+s);
}
}
if(z != 0){
u = z;
}
x = 0;
y = 0;
System.out.println("here");
}
System.out.println("z is" +z);
}
}
Thanks.