Java End-of-file

Sort by

recency

|

1153 Discussions

|

  • + 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());
            
        }
    }
    
  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
    
            int nLine = 1;
    
            while (scanner.hasNext()) {
                String line = scanner.nextLine();
                
                System.out.println(String.format("%d %s", nLine, line));
                
                nLine++;
            }
            
            scanner.close();
        }
    }
    
  • + 0 comments
        Scanner sc = new Scanner(System.in);
        for (int lineNum = 1; sc.hasNext(); lineNum++) {
            System.out.println(lineNum + " " + sc.nextLine());
        }
    
        sc.close();
    }
    
  • + 0 comments

    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);
        for (int lineNum = 1; sc.hasNext(); lineNum++) {
            System.out.println(lineNum + " " + sc.nextLine());
        }
    
        sc.close();
    }