d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Number Of Arrays Based Off Input
Add Reply New Topic New Poll
Member
Posts: 10,660
Joined: Oct 9 2010
Gold: 373.00
Feb 25 2015 02:51pm
is there a basic way like using a for loop to create a number of arrays based off of input all arrays would be the same size

ie. the user enters a 5 and and a 6 and then the program would create 5 arrays with the size of 6

dont need the code just wondering if it is doable without advanced methods
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Feb 25 2015 03:17pm
either store them in a list or an array

ex...

Code

{
List<int[]> arrays = new ArrayList<int[]>( );
for ( int i = 0; i < 5; i++ ) {
arrays.add( new int[6] );
}
}
//or
{
int[][] arrays = new int[5][];
for ( int i = 0; i < 5; i++ ) {
arrays[i] = new int[6];
}
}
Member
Posts: 10,660
Joined: Oct 9 2010
Gold: 373.00
Feb 25 2015 03:57pm
Quote (labatymo @ Feb 25 2015 04:17pm)
either store them in a list or an array

ex...

Code
{
List<int[]> arrays = new ArrayList<int[]>( );
for ( int i = 0; i < 5; i++ ) {
arrays.add( new int[6] );
}
}
//or
{
int[][] arrays = new int[5][];
for ( int i = 0; i < 5; i++ ) {
arrays[i] = new int[6];
}
}


damn thanks

we cant use 2d arrays and we havent done anything with lists so id imagine we cant use those either


if someone could point in the right direction for this question I would be appreciative
Code
In a gymnastics or diving competition, each contestant's score is calculated by dropping the lowest and highest scores and then adding the remaining scores. A judge awards points between 1 and 10, with 1 being the lowest and 10 being the highest. Write a program that will read judges' scores from an input file (there will be between 5 and 10 scores) and output the points received by the contestant, formatted with two decimal places. For example, Input file contains: 9.2 9.3 9.0 9.9 9.5 9.5 9.6 9.8 Dropped scores: 9.0 and 9.9 Points received: 56.90 Since you do not know the exact number of scores you will need to count the scores as they are read from the input file and use this as the actual size, or number of elements actually stored in your array.



example of possible input file

Code
Chen Ruolin 9.2 9.3 9 9.9 9.5 9.5 9.6 9.8
Emilie Heymans 9.2 9.2 9 9.9 9.5 9.5 9.7 9.6
Wang Xin 9.2 9.2 9.1 9.9 9.5 9.6 9.4 9.8
Paola Espinosa 9.2 9.3 9.2 9 9.5 9.3 9.6 9.8
Tatiana Ortiz 9.2 9.3 9 9.4 9.1 9.5 9.6 9.8
Melissa Wu 9.2 9.3 9.3 9.7 9.2 9.2 9.6 9.8
Marie-Eve Marleau 9.2 9.2 9.2 9.9 9.5 9.2 9.3 9.8
Tonia Couch 9.2 9 9.1 9.5 9.2 9.3 9.4 9.6
Laura Wilkinson 9.7 9.1 9.3 9.4 9.5 9.4 9.6 9.2


my original plan was to make separate arrays for each competitor but because that can change I cant
so should I make just two arrays one for the names and then one for the scores? and use some kind of for loop to read only the first x integers and then somehow get the min and max from those then get the total and then put that value into another array to hold it?

This post was edited by Beat on Feb 25 2015 04:00pm
Member
Posts: 10,660
Joined: Oct 9 2010
Gold: 373.00
Feb 25 2015 05:08pm
I can't edit anymore but I figured it out thanks again

This post was edited by Beat on Feb 25 2015 05:08pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll