Java End-of-file

Sort by

recency

|

1167 Discussions

|

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

    }

  • + 0 comments

    import java.io.; import java.util.; import java.util.concurrent.atomic.AtomicInteger;

    public class Solution {

    public static void main(String[] args) {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            AtomicInteger counter = new AtomicInteger(1);
            reader.lines()
                .map(line -> counter.getAndIncrement() + " " + line)
                .forEach(System.out::println);
        } catch (IOException e) {
            System.out.println("blew up");
        }
    }
    

    }

  • + 0 comments

    Java 15 Solution using StringBuilder class:

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

    public class Solution {

    public static void main(String[] args) {
        StringBuilder builder = new StringBuilder();
    
        Scanner scan = new Scanner(System.in);
    
        int i = 1;
        while(scan.hasNext()) {
            builder
            .append(i)
            .append(" ")
            .append(scan.nextLine())
            .append("\n");
            i++;
        }
    
        scan.close();
    
        System.out.print(builder.toString());
    }
    

    }

  • + 1 comment

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

    }