Krithi
asked

Expert
Abhay Jajodia answered
Hi Krithi,
java.util.Scanner is used to take input from the user, like reading a number or a word from the keyboard.
class Main is the main container for your program. Java code must be inside a class, and the program starts running from the main() method inside that class.
Example:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println(x);
}
}
If you have more questions, I am here to help 😊
Java
This question was asked as part of the Learn Java Basics course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer