'if' statement should only be working when there is input but when there is no input 'else' statement should be working.
But for some reason else is not working and not giving any output when there is no input.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t-->0) {
int k=s.nextInt();
int rem=0;
int j=0;
while(rem>=0) {
if(s.hasNextInt()) {
rem=rem+s.nextInt()-k;
}
else{
rem=rem-k;
}
j++;
}
System.out.println(j);
}
}
catch(Exception e) {
return;
}
}
}
Aucun commentaire:
Enregistrer un commentaire