小编G V*_*eep的帖子

查找适当的Java数据类型

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)

java int byte short long-integer

6
推荐指数
1
解决办法
1429
查看次数

Java 文件结尾

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)

java string eof

0
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×2

byte ×1

eof ×1

int ×1

long-integer ×1

short ×1

string ×1