java的hasNext()的用法

來源:互聯網
上載者:User

標籤:bsp   ati   ann   bbr   bre   rap   ack   computer   problem   

Java End-of-fileby Shafaet
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial 

"In computing, End Of File (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source." — (Wikipedia: End-of-file)

The challenge here is to read  lines of input until you reach EOF, then number and print all  lines of content.

Hint: Java‘s Scanner.hasNext() method is helpful for this problem.

Input Format

Read some unknown  lines of input from stdin(System.in) until you reach EOF; each line of input contains a non-empty String.

Output Format

For each line, print the line number, followed by a single space, and then the line content received as input.

Sample Input

Hello worldI am a fileRead me until end-of-file.

Sample Output

1 Hello world2 I am a file3 Read me until end-of-file.
 
import java.util.*;import java.io.*;import java.text.*;import java.math.*;import java.util.regex.*;class Main{            public static void main(String[] args) {           Scanner scan = new Scanner(System.in);           for(int i = 1; scan.hasNext(); i++){               System.out.println(i + " " + scan.nextLine());           }        }       // sc.close();            }

  

java的hasNext()的用法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.