Java End-of-file

Sort by

recency

|

1164 Discussions

|

  • + 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());
    }
    

    }

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

    }

  • + 0 comments

    This is a great challenge for anyone learning Java! Cricbet99 club login

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

    }

  • + 0 comments
        Scanner x= new Scanner(System.in);
        int i = 1;
        while(x.hasNext()){
            System.out.printf("%d %s%n", i++, x.nextLine());
        }
                x.close();
                don't forget close scanner