Exception in thread "main" java.util.NoSuchElementException 10
atjava.util.Scanner.throwFor(Scanner.java:838)atjava.util.Scanner.next(Scanner.java:1...
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Main.main(Main.java:10)
我的程序老是报错怎么解决,就是输出二进制第k位的数为一时为YES
import java.util.Scanner;
public class Two {
public static void main(String[] args) {
int N,k,n1,n2=0,times=0;
Scanner scan1 = new Scanner(System.in);
Scanner scan2 = new Scanner(System.in);
N=scan1.nextInt();
k=scan2.nextInt();
n1=N;
while(n1>0&&1<=N&&N<=(Math.pow(2,23)-1)){
n2=n1%2;
n1=n1/2;
times++;
if(times==k+1)
break;
}
if(n2==1)
System.out.println("YES");
else
System.out.println("NO");
// TODO Auto-generated method stub
}
} 展开
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Main.main(Main.java:10)
我的程序老是报错怎么解决,就是输出二进制第k位的数为一时为YES
import java.util.Scanner;
public class Two {
public static void main(String[] args) {
int N,k,n1,n2=0,times=0;
Scanner scan1 = new Scanner(System.in);
Scanner scan2 = new Scanner(System.in);
N=scan1.nextInt();
k=scan2.nextInt();
n1=N;
while(n1>0&&1<=N&&N<=(Math.pow(2,23)-1)){
n2=n1%2;
n1=n1/2;
times++;
if(times==k+1)
break;
}
if(n2==1)
System.out.println("YES");
else
System.out.println("NO");
// TODO Auto-generated method stub
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询