473,403 Members | 2,071 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,403 software developers and data experts.

How to make a loop that takes user input and puts it into an array

Hi, I'm trying to make a loop that fills each of the 10 places in the array with a value, however i cant figure out how to make the loop end once all the slots in the array are finished. Thanks
May 28 '15 #1
3 1374
chaarmann
785 Expert 512MB
Please show the code that you have done so far and we can point out how to correct it.

Without that, we can only give you general tips, that you probably already know. Like:
To end a loop, just use 'break'.
Or just use "for(int i = 0; i < 10; i++){...}" that will end automatically after 10 steps.
May 28 '15 #2
here is my code

Expand|Select|Wrap|Line Numbers
  1. //Brandon Dixon, CRHS
  2. import java.io.*;
  3.  
  4. public class J13Q1
  5. //finds the average of an array of numbers
  6. {
  7.     public static void main(String[]args) throws IOException
  8.     {
  9.      double[] numbers = new Double [10];
  10.  
  11.        While numbers <= [10]
  12.         {
  13.           System.out.println("please enter a number");
  14.           numbers = stdin.readline();
  15.         }
  16.  
  17.           System.out.println ("you entered " + numbers[1] + ", " + numbers [2] + numbers[3] + ", " + numbers [4] + numbers[5] + ", " + numbers [6] + numbers[7] + ", " + numbers [8] + numbers[9] + ", " + numbers [10]);
  18.      }
  19. }

attacked is also an error message I'm getting that I don't understand.
Attached Images
File Type: png Capture.PNG (2.2 KB, 74 views)
May 28 '15 #3
computerfox
276 100+
The function you should use is scanner.nextint().
You can put it in a loop like this:

Expand|Select|Wrap|Line Numbers
  1. Scanner scan=new Scanner();
  2. for(int i=0;i<10;i++){
  3.  numbers[i]=scan.nextInt();
  4. }
  5.  
Then you can loop through the array or whatever you want.

http://www.tutorialspoint.com/java/u...er_nextint.htm
May 29 '15 #4

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

Similar topics

23
by: ern | last post by:
I have a program that runs scripts. If the user types "script myScript.dat" the program will grab commands from the text file, verify correctness, and begin executing the script UNTIL... I need...
7
by: Stephen | last post by:
Hi I need to set up a table or datagrid where the user is able to input values directly into the cells. What i am attempting to build is a page that displays all the days of the year with the...
2
by: danielboendergaard | last post by:
Hey Im making a homepage in php. I use a html form to put data into mysql and i want to make some buttons which inserts user input values into a textarea. I have used a button like this: <input...
1
by: kingshuk | last post by:
OS : WinXp ORACLE VERSION : Oracle 10g I m unable to use the loop in PL/SQL with user input. When ever i am going to use the block of code is shows error...... /* TABLE WITH DATA TYPE */ ...
6
by: michelle eccles | last post by:
I have an array with limit of 5 values. The code as writen allows the user to enter a 6th number before averaging the first five number. I want to stop the user from being able to enter that 6th...
1
by: Dubyer | last post by:
Hi everyone, I am taking Java for the first time(required for my degree), and I am looking for help with a program I need to create. I have searched the forums, but none of them meet the criteria...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.