Ad
  • Home
  • Forums
  • COMPUTER
  • 💻 Coding & Programming

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

  • Thread starter Thread starter Princess Serrano
  • Start date Start date Aug 2, 2017
Status
Not open for further replies.
P

Princess Serrano

Honorary Poster
  • Aug 2, 2017
  • #1
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
 
H

HH_PRINCE

Honorary Poster
  • Aug 2, 2017
  • #2
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")
 
H

HH_PRINCE

Honorary Poster
  • Aug 2, 2017
  • #3
BTW for importing JOption

#code : import javax.swing.JOptionPane;
 
H

HH_PRINCE

Honorary Poster
  • Aug 2, 2017
  • #4
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
 
J

jay3244

Enthusiast
  • Aug 2, 2017
  • #5
may apps ka na ginagamit boss o hardcoding ka?
kasi netbeans gamit ko boss, calling sa mga functions madali lng.
 
H

HH_PRINCE

Honorary Poster
  • Aug 2, 2017
  • #6
yeah, madali lang mag-code sa netbeans madaling makita yung errors
 
Status
Not open for further replies.

Popular Tags

android api app arduino bot c c++ capstone capstone project code coding coding and programming course css database developer development free help how how to html in java javascript language laravel mag mysql need need help patulong php program programmer programming programming language project python question react sql system thesis tutorial udemy using visual basic web with
Share:
Facebook X Bluesky LinkedIn Reddit Pinterest Tumblr WhatsApp Email Share Link
  • Home
  • Forums
  • COMPUTER
  • 💻 Coding & Programming
  • View Non-AMP Version
  • Contact us
  • Terms and rules
  • Privacy policy
  • Help
  • Home
Menu
Log in

Register

  • Home
    • Shoutbox
    • Miscellaneous
    • Mobile Network
    • Internet
    • Mobile Phone
    • Media
    • Computer
    • Game
    • Lounge
  • Forums
    • New topics New questions Popular today Popular this month New posts
  • What's new
    • Featured content
    • New posts
    • New media
    • New media comments
    • Latest activity
  • Media
    • New media
    • New comments
    • Search media
  • Search
    • Advanced search
X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?

X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?