Java End-of-file

Sort by

recency

|

1117 Discussions

|

  • + 0 comments

    solution:

    Scanner in = new Scanner(System.in); int lineNumber=1; while (in.hasNextLine()) { String line = in.nextLine(); System.out.println(lineNumber + " " + line); lineNumber++; //

  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int a = 0;
        String s;
        while(sc.hasNext()){
            s = sc.nextLine();
            a++;
            System.out.println(a+" "+s);
            if(s.endsWith("Read me until end-of-file."))
                break;
        }
    
         /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    }
    

    }

  • + 0 comments

    Scanner sc = new Scanner(System.in); String x = sc.nextLine(); String y = sc.nextLine(); String z = sc.nextLine(); System.out.println("1 "+x); System.out.println("2 "+y); System.out.println("3 "+z);

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

    }

  • + 0 comments

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

    public class Solution {

    public static void main(String[] args) {
        Scanner readObj = new Scanner(System.in);
        int i = 1;
        while(readObj.hasNext()){
            String line = readObj.nextLine();
            System.out.println(i+" "+line);
            i++;
        }
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    }
    

    }