How to get input from keyboard scanner into an array
This is probably a very basic question but I'm very new to java..
My task is to reverse a string of five digits which have been entered using keyboard scanner.
E.g. - Entered number - 45896
Output - 69854
I used the StringBuffer(inputString).reverse() command for this, but i need a more basic method to do this.
I thought of defining an array of 5
int[] array = new int [5];
and then using,
Scanner scan = new Scanner(System.in);
to enter the numbers. But I can't figure out how to get the five input numbers into the array.
If I can do this I can print the array in reverse order to get my result.
Any other simple method is also welcome.
Hey thanks for the quick reply,
But how can I assign the whole five digit number into the array at once without asking to enter numbers separately?
E.g. - if entered number is 65789
Assign digits into positions,
anArray [0] = 6;
anArray [1] = 5;
anArray [2] = 7;
anArray [3] = 8;
anArray [4] = 9;
I'm really sorry but I am very new to the whole subject.
Similar Messages
-
How to read input from handheld scanner on a keyboard port
Hi everybody,
i have an application that should read input from a scanner.
If i use a jTextField to input scanned data it works fine.
the problem is that i don't want to use any text component to input data into it.
And if i set the jtextField not visible then the focus sustem doesnt work.
I tried to read a buffered input stream from System.in but it doesnt work.
If the scanner was installed on a serial port i could use javax.comm to monitor it.
But unfortunately i must use the keyboard wedge thing...
Do you have any ideas?
Thank you in advanceBufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))
null -
How to get input from card reader
hi, everyone,
I have a project, which needs me to get input from card reader. My terminal input is IBM POS system, but it didnot provide the API to get the input. How can I get the input? Need your help so much! and thanks a lotNow this is a wild idea.... how about searching the IBM site for technical information ?
-
How to Get Input from Command Prompt?
How can i get input from command prompt like
C:\
or linux ?
(Here's what I use now)
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line;
Whlie((line=in.readLine())!= null)
{ System.out.prinln( line) ; }
IS THERE A BETTER WAY?The main method within a java class accepts command line input through a String array.
In this example args is the String array. You can access the parameters as args[0] for the first parameter, args[1] for the second parameter, etc....
The usage for the example below would be :
c:\EDIFormat file1 file2
Where args[0] would equal file1 and args[1] would equal file2.
public class EDIFormat {
public static void main(String[] args) {
if (args.length < 0) {
System.out.println("No Parameters supplied. Exiting....");
// open input and output files
EDIFiles(args[0], args[1]);
Hope that helps! -
How to save input from radio buttons into textfiles, Help
Below is my code. Currently it gets the input from the textbox "Date" and places it into a textfile using "getText"
How do i get the input from a radio button?
i think getselected only works on JLists.
String a = bookNo.getText();
out = new PrintWriter(new FileOutputStream("" + a +".txt"));
out.println("Date: " + tDate.getText());
out.close();
catch(IOException ex)
System.out.println("Error");
Your help is appreciatedSorry, here's my code. The point of the system is to write information from the page, onto the textfile named "something.txt"
public void write() {
String fullfile = "something.txt";
try {
BufferedWriter out = new BufferedWriter(new FileWriter(fullfile));
out.write("");
out.write("HOLIDAY BOOKING SYSTE,");
out.write("");
out.write("SECTION 4.0 DESITNATION");
out.write("");
out.write("Holiday Destination: " + list.getSelectedValue());
out.write("Duration of holiday: ");
out.write("");
out.write("SECTION 5.0 TRAVEL RESERVATION DETAILS");
out.write("Airport for depature and return");
out.write("Depature Date: " + txtDateD.getText());
out.write("Depature Time: " + txtTimeD.getText());
out.write("Arrival Date: " + txtDateA.getText());
out.write("Arrival Time: " + txtDateA.getText());
out.write("Holiday Destination: " + txtbookingno.getText());
out.write("Customer Booking Information");
out.close();
} catch (IOException f) {
//end of file writer
The code below is for the radio buttons, The choice is to either pay for an "Economic" ticket, or a "First Class" ticket. If a customer selects the economic ticket radio button, what line of coding do i add to the write method above, to show "Economic ticket"
Also i ran into another slight problem, theres a textbox called "Fine" in another form called "page1", how do i call it's value i.e. what line of code do i place for it in the method above? -
Hard disk failure, replaced; how to get songs from iPod back into iTunes
Hard disk failure, replaced with new hard drive etc;
How do I get all songs from iPod back into iTunes?
(mix of CD sourced and iTunes shop sourced)I can't believe there's no answer to this. Apple wants to charge customers for support but this has got to be happening thousands of times a day what with Windows OS reinstalls being what they are-numerous! Please let me know if/when you get a reply, thx!
-
How to Get input from User and Display it's Value
Hi ,
I need to get 2 inputs from user and to display it's Mutilple Value.
The Below Code is working fine to get 2 Input's from user,but it display a Junk value as a Result .How to
overcome this Problem. I need to display it's Mutilple(a*b) value of "a " and " b".
import java.io.*;
class Mul{
static int a=0;
static int b=0;
static int Count=0;
public static void main(String args[])throws IOException{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
do{
a=(char)br.read();
Count++;
b=(char)br.read();
if(Count==2)
System.out.println("The Multiplied Value is "+a*b);
}while(Count<2);
}Changed to Integer but still the problem persists.
import java.io.*;
class Mul{
static int a=0;
static int b=0;
static int Count=0;
public static void main(String args[])throws IOException{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
do{
a=(int)br.read();
Count++;
b=(int)br.read();
if(Count==2)
System.out.println("The Multiplied Value is "+a*b);
}while(Count<2);
} -
How to Get Input From User and Display Result
Hi ,
I need to get 2 inputs from user and to display it's Mutilple Value.
The Below Code is working fine to get 2 Input's from user,but it display a Junk value as a Result .How to
overcome this Problem. I need to display it's Mutilple(a*b) value of "a " and " b".
import java.io.*;
class Mul{
static int a=0;
static int b=0;
static int Count=0;
public static void main(String args[])throws IOException{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
do{
a=(char)br.read();
Count++;
b=(char)br.read();
if(Count==2)
System.out.println("The Multiplied Value is "+a*b);
}while(Count<2);
}Hi ,
I need to get 2 inputs from user and to display it's
Mutilple Value.
The Below Code is working fine to get 2 Input's from
user,but it display a Junk value as a Result .How
to
overcome this Problem. I need to display it's
Mutilple(a*b) value of "a " and " b".
import java.io.*;
class Mul{
static int a=0;
static int b=0;
static int Count=0;
public static void main(String args[])throws
IOException{
BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
do{
a=(char)br.read();This line will get you the ascii-value of the typed character.
This line will not get you the value typed in.
Try looking for Integer.parseInt()...
Count++;
b=(char)br.read();
if(Count==2)
System.out.println("The Multiplied Value is "+a*b);
}while(Count<2); -
How to get photos from txt msgs into gallery, and to my home pc
I have no problem getting photos from Gallery into my home PC (Windows 7) using the USB cord. I cannot figure out how to save a photo which has been sent to me via txt msg. tried the bottom left menu, and nothing there to help.
Try doing a long press directly over photo, see if it brings up a menu of options to do to the attachment/photo. One should be "Save to storage" or something like that.
-
JComboBox How to get input from JComboBox
Hi all.
I have a JComboBox called combobox.
User can choose one string out of 5 using this JComboBox.
Whenever the user press a button, I'd like to get an input through this combobox using actionListener.
How can I get input through JComboBox?
combobox.getValue() ???
I appreciate your help !http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComboBox.html
Object getSelectedItem() -
How to get songs from iPod back into iTunes library?
My computer recently crashed and all my files were deleted, so now i have all my songs on my iPod but not on my iTunes, how can i put my songs back into my library without my whole iPod being erased?
Recover media from iPod
See this post from forum regular Zevoneer for options on moving your iPod data back to your computer.
tt2 -
I'm dumb, can't figure how to get playlist from itunes library into my itou
Ok, I have looked and looked and did search. I want to copy a few playlists from my itunes library into my itouch. I was told they would transfer when I synched, they didn't. Drag and drop does not do the job. What am I missing? I am sure something very very simple. HELP. I do NOT want to do the playlist again in my itouch from scratch, as I have almost 1,000 songs to search through.
There has got to be an easier way.katinak67 wrote:
I was told they would transfer when I synched, they didn't.
"Synch" is the process whereby files get copied from the iTunes library to the iPod. If your playlists did not copy, what actually did happen when you synched? -
How to get data from MS CRM into Crystal Reports
Hello All,
Can anybody tell me how to get data into crystal XI reports with MS CRM.
Thanks in Advance
RameshFirst you should refer to the Rules of Engagement and then add more info.
Start off by telling us what version of CR are you using and what is MS CRM?
Thank you
Don -
How to get input from BARCODE Reader
using oracle forms builder...........in form text box
Yes I actually used such a reader way back with forms 2.0.
It connects into the keyboard lead so as far as the form is concerned it is exactly the same as typed input. Such readers can also be programmed to send a <return> at the end of the string to fire validation and move to the next field. The keyboard emulation method is also ideal when an unreadable barcode is encountered as the operator can just take over and type it in manually. -
How to get data from maintaince view into internal table
Hi,
I want to get the all data from v_t179 (maintanence view) into intrenal table.
if i write select stmt , it is giving error.
I want all data into internal table.
regards,
AjayI think this is what you want:
TABLES: t179, t179t.
DATA: v_t179_int TYPE TABLE OF v_t179.
SELECT * FROM t179
JOIN t179t ON
t179~prodh = t179t~prodh
INTO CORRESPONDING FIELDS OF TABLE v_t179_int.
Rob
Maybe you are looking for
-
How to - Build a report based on dynamic query
I am using this how to and find out that there is an syntax error on this example, where the and should be where. I got an SQL parsing error when I followed this example until I debugged with the debug while on this page. Has any one using this how t
-
How to get correct number of hours from a total calculated hours
Hi all I'm trying to calculate the number of actual hours. so the hours look like this A: 1hr 30min B: 1hr 40min if i add those up i get C: 2hr 70min (ie 1.30+1.40=2.70) however, I want to actually display the actual hours which is 3hr 10min I had th
-
Some of my songs in itunes wont play
some of my songs in itunes wont play. several songs show up but instantly pause when selected and wont play. They play fine on the computer, doesnt seem to be a sync or space issue. Any suggestions?
-
Duplicate content, please see: https://community.verizonwireless.com/message/1112817#1112817 Message was edited by: Admin Moderator
-
My iphone not recognize by my pc
From a week my iPhone stopped responding to my PC. When I plug the cable in.. nothing. Not loading, not even a sound. PC has same reaction - no iTunes and no mass storage device.. And its not listed in the Portable devices. I've reinstalled iTunes, A