Java End-of-file

Sort by

recency

|

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

    The Java End-of-File (EOF) challenge is a great exercise for practicing input handling and loop control. cricketbuzz.com login id

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