Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Value of variable required to be entered by user.
Vishnu Sharma
Ranch Hand
Posts: 55
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I want in my code a
String
value, that is entered by the user, which method i can use for it, as we use scanf in C language.
Regards,
Vishnu
Maneesh Godbole
Bartender
Posts: 11497
19
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Where is the user going to enter? Swing component? Web component? Console?
[
How to ask questions
] [
Donate a pint, save a life!
] [
Onff-turn it on!
]
Jonas Isberg
Ranch Hand
Posts: 118
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am guessing that scanf in C takes input from the console.
One way to do that in
java
is to use System.in (there might
be more friendly alternatives).
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class ReadString { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Say something: "); String input = reader.readLine(); System.out.println("You said: " + input); } }
Maneesh Godbole
Bartender
Posts: 11497
19
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Since 1.5 the ideal way would be the java.util.Scanner class
[
How to ask questions
] [
Donate a pint, save a life!
] [
Onff-turn it on!
]
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
NX:Formatted textField
How to restrict data in JTextField?
Setting value for a key programmatically for arg0 tag
JPopUPmenu Problem of PopUp scroll
Switch between class implementation
More...