Java End-of-file

Sort by

recency

|

1140 Discussions

|

  • + 0 comments

    Well, that was my soluction:

    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 str = new Scanner(System.in);
    
    
        for(int i = 1; str.hasNext(); i++){
            String N = str.nextLine();
            System.out.println(i + " " + N);
        }
    }
    

    }

  • + 0 comments

    My Solution is here, if you any have any feedback you can write a comment.

    public class Solution {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        List<String> lines = new ArrayList<>();
        int counter = 0;
    
        while(input.hasNext()){
            counter++;
            String unKnownLine = input.nextLine();
    
            lines.add(counter + " " + unKnownLine) ;
        }
        input.close();
    
        for (String n : lines) {
            System.out.println(n);
        }
    
    }  
    

    }

  • + 0 comments

    // Here is simple solution with a coutner veriable and using hasNextLine() method. While loop will iterate and give number of iterations a number of lines in input.

    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. */
        Scanner sc = new Scanner(System.in);
    
        int n =1;
    
        while (sc.hasNext()) {
            System.out.println(n +" " + sc.nextLine());
            n++;
        } 
    
        }
    
    }
    
  • + 0 comments

    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. */
        Scanner sc = new Scanner(System.in);
        ArrayList x = new ArrayList<>();
        int count = 0;
        while (sc.hasNext()) {
            count++;
            String input = sc.nextLine();
            x.add(count+" "+input);
        }
        for (Object i:x){
            System.out.println(i);
        }
    
    }
    

    }

  • + 0 comments

    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. */
        Scanner TakesInput= new Scanner(System.in);
        int count=1;
        while (TakesInput.hasNextLine()) {
             String Input= TakesInput.nextLine();
            System.out.println(count++ +" "+Input);
    
        }
    }
    

    }