public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNextLine()) {
BigInteger number = new BigInteger(input.nextLine());
int bitLength = number.bitlength();
if (bitLength <= Bytes.SIZE)
System.out.println("\u8211 byte");
if (bitLength <= Short.SIZE)
System.out.println("\u8211 short");
if (bitLength <= Int.SIZE)
System.out.println("\u8211 int");
if (bitLength <= Long.SIZE)
System.out.println("\u8211 long");
if (bitLength > Long.SIZE)
System.out.println(number + " can't be fitted anywhere.");
}
}
Run Code Online (Sandbox Code Playgroud)
任务:找到合适的数据类型示例输入:5
-150
150000
1500000000
213333333333333333333333333333333333
-100000000000000
Run Code Online (Sandbox Code Playgroud)
样本输出:
-150 can be fitted in:
short
int
long
150000 can be fitted in: …
Run Code Online (Sandbox Code Playgroud) import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner line = new Scanner(System.in);
int counter = 1;
while (line.hasNextLine()) {
String line = line.nextLine();
System.out.println(counter + " " + line);
counter++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
任务:每一行将包含一个非空字符串。读取直到EOF。对于每一行,打印行号,后跟一个空格和行内容。
输入示例:
Hello world
I am a file
Read me until end-of-file.
Run Code Online (Sandbox Code Playgroud)
示例输出:
1 Hello world
2 I am a file
3 Read me until end-of-file.
Run Code Online (Sandbox Code Playgroud)