🔒 Closed How to ask user in java? input in java.

Status
Not open for further replies.

Princess Serrano

Honorary Poster
Tanong lang guys. Paano po mag input sa java? Like cin>> in c++
Pati pede po bang mag input on the same line? For example

I ask the user

Input your last name:

After filling up the question and hit enter, may lalabas na pangalawang tanong na kahanay din nung unang tanong. Is that possible?

Another question, how to hide characters while person is typing the code. Thanks.

Java programming po
 
tHERE are two methods para mag-input sa java

1 : Scanner

dapat import mo muna si Scanner

#code : import java.util.Scanner;

Scanner input = new Scanner(System.in); = ito yung para tawagin si Scanner or method ni scanner.

then ,


System.out.print("Enter your name : ");
//Print nya yung Enter your name

System.out.println("Enter your name : ");
//Kung ln is for next line
name = input.nextLine();
//manghihingi na sya ng input , remember .nextLine for String, .nextInt for Integer, .nextDouble for double and etc. research mo nalang.

input : lastname

output ng :
System.out.print("Enter your name : ");
name = input.nextLine();

== Enter your name : lastname

System.out.println("Enter your name : ");
name = input.nextLine();

==Enter your name :
lastname

so kung gusto mong in the same line lahat inputs mo ..
then huwag mong lagyan ng (ln).
and after filling the first question the second question will print-out.
ex:
System.out.print("Enter your firstname : ");
firstname = input.nextLine();
System.out.print("Enter your lastname : ");
lastname = input.nextLine();

output : Enter your firstname : firstname Enter your lastname : lastname

2. JOption ,dahil di mo sya needed di kona eexplain BTW bibigyan kita ng examples.
Di katulad ng Scanner na piprint lang nya , yung JOption ay POP-op method

code ex's:

for string : name = JOptionPane.showInputDialog(null,"Enter your Name:");

for int : number = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter a number :"));
Integer.parseInt = cinoconvert nya ang string to int because kung walang parsing di ang tinatanggap lang ni JOption ay string.

pop-up message only = JOptionPane.showMessage(null,"Sana nakatulong sayo")
 
there's a way to hide characters..
clear the scanner console ..

and this is the code I used before ..
#code : in.NextLine();
just try It cause I'm not so sure kung walang kulang sa code because I'm focusing now in PHP/web
 
may apps ka na ginagamit boss o hardcoding ka?
kasi netbeans gamit ko boss, calling sa mga functions madali lng.
 
Status
Not open for further replies.

About this Thread

  • 5
    Replies
  • 779
    Views
  • 3
    Participants
Last reply from:
HH_PRINCE

Trending Topics

Online now

Members online
1,061
Guests online
937
Total visitors
1,998

Forum statistics

Threads
2,274,911
Posts
28,959,286
Members
1,233,484
Latest member
asawakoo03
Back
Top