Lesson 4 :- Importance of user inputs.

In the previous lesson, we got some numbers without using user. In the real world, the inputs are given by users. So we need to know how to get user inputs. This lesson is created to teach it.

Understand about the user inputs using this code.

Special things are we import a class & create an object. You can understand Scanner class and object creation by following the lesson series.

import java.util.Scanner;
class New{
     public static void main(String[} args){
           Scanner s = new Scanner(System.in);
       
      System.out.print("Enter a String: ");
      String a = s.next();
      System.out.println("String is "+a);

      System.out.print("Enter an integer: ");
      int b = s.nextInt();
      System.out.println("Integer is "+b);

     }
}



     





















Try to create a simple calculator using user inputs.




























Comments

Popular posts from this blog

Lesson 1

Lesson 6 :- Calling a method

Lesson 8 :- Creating an object.