Java Scanner类异常
Exceptioninthread"main"java.util.NoSuchElementExceptionatjava.util.Scanner.throwFor(S...
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1371)
at Main.main(Main.java:14)
以下是源码
import java.util.Scanner;
public class _1002
{
public static void main(String[]args)
{
int line = new Scanner(System.in).nextInt();
String[] bit1 = new String[line] ,
bit2 = new String[line];
for(int i = 0; i < line; i ++)
{
String s = new Scanner(System.in).next();
bit1[i] = s;
if(bit1[i].endsWith("MB"))
{
bit2[i] = Integer.parseInt(bit1[i].substring(0 , bit1[i].length() - 2)) * 8388608 + "bit";
}
else
{
if(bit1[i].endsWith("KB"))
{
bit2[i] = Integer.parseInt(bit1[i].substring(0 , bit1[i].length() - 2)) * 8192 + "bit";
}
else
{
if(bit1[i].substring(bit1[i].length() - 1).equals("B"))
{
bit2[i] = Integer.parseInt(bit1[i].substring(0 , bit1[i].length() - 1)) * 8 + "bit";
}
else
{
bit2[i] = bit1[i];
}
}
}
}
for(String x : bit2)
{
System.out.println(x);
}
}
} 展开
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1371)
at Main.main(Main.java:14)
以下是源码
import java.util.Scanner;
public class _1002
{
public static void main(String[]args)
{
int line = new Scanner(System.in).nextInt();
String[] bit1 = new String[line] ,
bit2 = new String[line];
for(int i = 0; i < line; i ++)
{
String s = new Scanner(System.in).next();
bit1[i] = s;
if(bit1[i].endsWith("MB"))
{
bit2[i] = Integer.parseInt(bit1[i].substring(0 , bit1[i].length() - 2)) * 8388608 + "bit";
}
else
{
if(bit1[i].endsWith("KB"))
{
bit2[i] = Integer.parseInt(bit1[i].substring(0 , bit1[i].length() - 2)) * 8192 + "bit";
}
else
{
if(bit1[i].substring(bit1[i].length() - 1).equals("B"))
{
bit2[i] = Integer.parseInt(bit1[i].substring(0 , bit1[i].length() - 1)) * 8 + "bit";
}
else
{
bit2[i] = bit1[i];
}
}
}
}
for(String x : bit2)
{
System.out.println(x);
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询