Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Can Anyone Explain the Output of This Program

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 93
    Answer it

    import java.util.*;
    public class Input {

        public static void main(String[] args) {
            Scanner s=new Scanner(System.in);
            System.out.println("Enter something");
            int a=s.nextInt();
            System.out.println("The thing entered is:"+a);
            Scanner w=new Scanner(System.in);
            System.out.println("Now enter a string");
            String q=s.nextLine();
            System.out.println("The entered String is:"+q);
            
        }

    }

 1 Answer(s)

  • first output if user enter a number is integer like input is 3 then output is 3
    if user enter string or character etc error exception would be there

    for second output it would be empty cause nextLine() is used 

    sample:- 
    Enter something
    3
    The thing entered is:3
    Now enter a string
    The entered String is:
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: