Java End-of-file

Sort by

recency

|

1121 Discussions

|

  • + 0 comments
    import java.io.*;
    import java.util.*;
    import java.util.Scanner;
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner scan = new Scanner(System.in);
        int line = 1;
        while(true){
        if (scan.hasNextLine()){
            System.out.printf("%d %s\n", line, scan.nextLine());
            line += 1;
        }
        else{
            break;
        }
        }
        }
        
    }
    
  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
    
    Scanner scanner=new Scanner(System.in);
    int lineNumber=1;
    while (scanner.hasNextLine()){
        String line=scanner.nextLine();
        System.out.println(lineNumber + " " + line);
        lineNumber++;
    } 
    scanner.close();
    }
    

    }

    **

  • + 0 comments
    import java.util.Scanner;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            
            int i = 1;
            while (scan.hasNextLine()) {
                System.out.printf("%d %s\n", i++, scan.nextLine());
            }
            
            scan.close();
        }
    }
    
  • + 0 comments

    import java.io.; import java.util.; import java.util.Scanner; public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int a = 0;
        String str;
        //Loop
        while (sc.hasNext()) {
        str = sc.nextLine();
        a++;
        System.out.println(a + " " + str);
        if (str.endsWith("Read me until end-of-file.")) { 
          break;
        }
        }
    }
    

    }

  • + 0 comments

    solution:

    Scanner in = new Scanner(System.in); int lineNumber=1; while (in.hasNextLine()) { String line = in.nextLine(); System.out.println(lineNumber + " " + line); lineNumber++; //