⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hasnextintdemo.java

📁 java编程代码
💻 JAVA
字号:

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class HasNextIntDemo
{
    public static void main(String[] args)
    {
        Scanner inputStream = null;

        try
        {
           inputStream =
              new Scanner(new FileInputStream("data.txt"));
        }
        catch(FileNotFoundException e)
        {
           System.out.println("File data.txt was not found");
           System.out.println("or could not be opened.");
           System.exit(0);
        }

        int next, sum = 0;
        while (inputStream.hasNextInt( ))
        {
            next = inputStream.nextInt( );
            sum = sum + next;
        }

        inputStream.close( );

        System.out.println("The sum of the numbers is " + sum);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -