The use of Java Hasnext ()

Source: Internet
Author: User

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

"In computing, End of File (commonly abbreviated EOF) are a condition in a computer operating system wher e No more data can is read from a data source. "-(Wikipedia:end-of-file)

the challenge are to read lines of input until you reach EOF, then number and print all lines of CO Ntent.

Hint: The Java ' s scanner.hasnext () method is the helpful for this problem.

Input Format

Read some unknown lines of input from stdin (system.in) until your reach EOF; each line of input cont Ains 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 ();            }

  

The use of Java Hasnext ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.