473,320 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Input

176 100+
How does the input function in java work?
Apr 23 '08 #1
14 1825
pronerd
392 Expert 256MB
How does the input function in java work?
What input method, in what object, in what library?
Apr 23 '08 #2
Kid Programmer
176 100+
What input method, in what object, in what library?
Input for strings and numbers. I don't know how to answer your questions. I'm new to java. Just do any of them.
Apr 23 '08 #3
pronerd
392 Expert 256MB
Input for strings and numbers. I don't know how to answer your questions. I'm new to java. Just do any of them.
Neither String or Number class has an input method. What is it you are trying to do?
Apr 23 '08 #4
Ganon11
3,652 Expert 2GB
Are you possibly asking how to input in Java?
Apr 23 '08 #5
Kid Programmer
176 100+
All I want to know is how you can prompt the user to enter a number or string.
Apr 23 '08 #6
Laharl
849 Expert 512MB
Prompting (aka output) can be done through System.out.println(), or System.out.print() if you don't want the newline. As to input, Scanner is what you want. You also might want to look at Sun's Java tutorials for all sorts of useful information.
Apr 23 '08 #7
BigDaddyLH
1,216 Expert 1GB
If you're using 1.6, I like java.io.Console in simple situations: http://java.sun.com/javase/6/docs/ap...o/Console.html
Apr 23 '08 #8
Kid Programmer
176 100+
System.out.println and System.out.print simply make a message appear. I want the user to actually be able to enter something. In the language python for example the command would be:

blah = input("please enter a number or word: ")
Apr 23 '08 #9
Laharl
849 Expert 512MB
Hence the link to the Scanner class I posted. The example code there shows how to use it as console-based input. Just remember to put 'import java.util.Scanner;' at the top of your file to use it. You have to use two commands to do the same thing as input("blah") in Python. One to output the string, one to read the input from the user.
Apr 23 '08 #10
Kid Programmer
176 100+
Okay I got it to work. Thanks. One more question. Is it possible to have the user only input a number.
Apr 23 '08 #11
sukatoa
539 512MB
Okay I got it to work. Thanks. One more question. Is it possible to have the user only input a number.
In console? That is impossible... but you can prompt the user if it is a wrong input.....

regards,
sukatoa
Apr 24 '08 #12
Kid Programmer
176 100+
In console? That is impossible... but you can prompt the user if it is a wrong input.....

regards,
sukatoa
How can you prompt the user if it is a wrong input?
Apr 24 '08 #13
sukatoa
539 512MB
How can you prompt the user if it is a wrong input?
Capture the user's input... ( variable should handle this )...

Compare it with what you want.... since it should be a number....

Convert it first into arrays of characters.
Loop in every element and compare it with digits... ( depends on how you will implement them )....

or simply put a try/catch block inside the conversion code...

Expand|Select|Wrap|Line Numbers
  1. try{
  2.      int digit = new java.util.Scanner(System.in).nextInt();
  3. }catch(InputMismatchException em){
  4.      new javax.swing.JOptionPane().showMessageDialog(null,
  5.                "BAD INPUT!!");
  6. }
regards,
sukatoa
Apr 24 '08 #14
Laharl
849 Expert 512MB
You can also use the Scanner's hasNextInt() method with a while loop to check if the user has entered an integer before you try to grab it or parse it at all.
Apr 24 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: gotcha | last post by:
I have a little code to add multiple items to a shopping cart based page. This code works perfect, but it adds all of the info to the same input fields every time it loops. I need it to change...
3
by: david | last post by:
HI! Im trying to make "HTML form" into automatic. 1. If I get 18 numbers like: A B C D E F . . . . 2. How can I put those 18 numbers automatically into 6 numbers format like: A B C D E F
2
by: SophistiCat | last post by:
Hi, I am working on a computational program that has to read a number of parameters (~50) from an input file. The program contains a single class hierarchy with about a dozen member-classes or...
2
by: Cranky | last post by:
Ok, here is my scenario: I need to input numbers using my handheld IPAQ. I figured out how to create an online numeric keypad for inputting numbers into an input field, what I need to know is how...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
3
by: cbradio | last post by:
Hi, I am having trouble developing a form in a restricted environment. My sample code is found below my message (sorry I don't have a URL). Basically, without a doctype, the form displays properly...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
13
by: cront | last post by:
I have a problem to work on: we will ask user to input anything and we will put that back onto the standard output with all set of brackets removed. We will not remove any single bracket e.g. ...
1
by: tcertain | last post by:
I am totally duh at javascript although I have 2 books trying to learn it. I am trying to add values to a form and have a calculate total at end. this is my form script. I have hours at end of...
1
by: printline | last post by:
Hello All I'm quite new to xml vs. PHP, so i hope someone can help with an issue i have been struggeling with. I have an html form, that when submitted, it should create an xml file, and save...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.