Java වල User Input දෙන්න පුලුවන් Progam එකක් හදන්නේ කොහොමද ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
import java.util.Scanner;
public class mypro {
public static void main(String args[ ] ) {
Scanner reader = new Scanner (System.in);
int nu = reader.nextInt ( );
}
}
1. මෙහි පළමු පේළියෙන් Java තුළ ඇති Scanner නම් Class එක Import කර තිබේ. 2,3 Codes Line Java Program වලදී සාමාන්යයෙන් තිබෙන ඒවාය.
2. 4 වැනි පේළියේදි Scanner Class එකට අදාළව ඇති System.in තුළවූ Data Read කරනු ලබයි. ඒ අනුව Keyboard එකෙන් Input ලබාගන්න භාවිතා කරන්නේ එම Data ය. මෙහිදී ඒවා ලබා ගන්නේ reader නම් Object එකටයි.
3. 5 වැනි පේළියේදි nu මගින් දැක්වෙන්නේ Int type Variable
එකකි. මෙය ක්රියාත්මක වන විට Use විසින් යමක් සටහන් කර
Keyboard එකේ Enter Button එක Press කළ සැනින් එම input එක nu නම් Variable එක තුළ Store කර ගනී.
Thanks You !
correct✔️
import java.util.Scanner; // import the Scanner class
class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
String userName;
System.out.println(“Enter username”);
userName = myObj.nextLine();
System.out.println(“Username is: ” + userName);
}
}
Use above msg’s