Java End-of-file

Sort by

recency

|

1127 Discussions

|

  • + 0 comments

    Java Solution==========================================

    import java.io.; import java.util.;

    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. */
        int count = 0;
    
        Scanner scanner = new Scanner(System.in);
    
    
        while (scanner.hasNext()) {
            String linea = scanner.nextLine();
            count ++;
            System.out.println(count +" "+linea);
        }
    
    }
    

    }

  • + 0 comments

    public class Solution {

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

    } }

  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
        int i = 1;
        ArrayList<String> light = new ArrayList<>();
        String EOF = "end-of-file";         
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextLine()){
    
            String token = scan.nextLine();
            if(token.toLowerCase().contains(EOF.toLowerCase())){
                light.add(token);
                break;
            }
            light.add(token);
        }
    
        for(String line : light){            
            System.out.println( i + " " + line);
            i++;
        }
    
    
                scan.close();
           }
    
  • + 0 comments

    simple loc:

    Scanner scan = new Scanner(System.in);
    int i =1;
    while(scan.hasNext()){
    		String line = scan.nextLine();
    		System.out.println(i+" "+line);
    		i++;
    }
            
    
  • + 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 sc= new Scanner(System.in);
        int lineNumber = 1;
        while(sc.hasNextLine()){
            String line = sc.nextLine();
            System.out.println(lineNumber+ " "+ line);
            lineNumber++;
        }
        sc.close();
    

    } }