Standard input and output | How get input in the Java | Output in Java
//Written in Java By Syed Ali Haider
//Student of The Hajvery
University,Lahore, Pakistan.
//Don't remove these lines for legal
use
//For more Please contact us.
import java.util.Scanner;// this is the
library import for getting the input from user
public class Java { // class is starts
from here
public static void main(String[] args) {// main function
starts from here
System.out.println("----------------------------------------------------");
System.out.println("\tThis the
way to show some text by using Java language\n");
System.out.println("Syed Ali
Haider");
System.out.println("The Hajvery
University, Lahore, Pakistan.");
System.out.println("----------------------------------------------------");
Scanner
name_of_object =new Scanner (System.in);
System.out.println("----------------------------------------------------");
System.out.println("\n\n\n\tThis
is the way to get input from user in Java.");
//here we prompt
user to enter the number, its just a message
System.out.println("Please enter
the roll number here: ");
// below
"Variable_name" is the name of variable in which "int"
value is store, "name_of_object" is
//the object for
getting the input, ".next" is the part if syntax, "Int"
show that only integer data is acceptable for
// for this
variable "();" is also a syntax
int variable_name = name_of_object.nextInt();
// here we show the
data entered by user
System.out.println("Your Roll
number is: " + variable_name);
// above the
"+" sign use as concatenate operator which is used to combine the two
thing together. such as in
// in above case,
The String "Your roll number is: " combine with the value of variable
whose name is "Variable_name"
System.out.println("----------------------------------------------------");
name_of_object.close(); // this is the
close to "name_of_objcet", which is used to get input from user, This
//this is the close
of input after that there is not input can be got by this object
}// main function is
end at here
}// class is end at here
//Written in Java By Syed Ali Haider
//Student of The Hajvery
University,Lahore, Pakistan.
//Don't remove these lines for legal
use
//For more Please contact us.
Comments
Post a Comment