Java End-of-file

Sort by

recency

|

1156 Discussions

|

  • + 0 comments

    Here's a very simple solution:

    import java.util.*;

    public class Solution {

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

    }

  • + 0 comments
    public class Solution {
    
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int line = 0;
            while (sc.hasNext()){
                String input = sc.nextLine();
                line += 1;
                System.out.println(line+" "+input);
            }
            sc.close();
        }
    }
    
  • + 0 comments
    while (sc.next()){
    System.out.println(i++ +" "+ sc.nextLine());
    }
    sc.close();
    
  • + 0 comments

    Scanner sc=new Scanner(System.in);

        for(int line=1; sc.hasNext(); line++){
            System.out.println(line+" "+sc.nextLine());
        }
        sc.close();
    
  • + 0 comments
    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) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner in = new Scanner(System.in);
            int i=1;
            do{
                String s=in.nextLine();
                System.out.printf("%d %s\n",i,s);
                i++;
            }while(in.hasNext());
            
        }
    }