English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

ok im taking a number in as user input and i want the array to be that long. My problem is this. Ok say i get 20 as the input. I want the array to be from 1-20 not 0-20. how do i do that. The way i have it now is this.
boolean answer[] = new boolean[number]; ( number being my input)

2007-09-09 13:44:37 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

I know what i have is right but i dont want it to be from 0-19. It has to be from 1-20 or it will not work.

2007-09-09 14:26:16 · update #1

4 answers

Then add 1 to the number input to create the array.
You now have an array of length 21 but with elements 1-20 as you require. You will just not be using element 0.

2007-09-09 21:20:17 · answer #1 · answered by AnalProgrammer 7 · 0 0

What you have is right. The array indicies will be 0-19 in your example.

2007-09-09 14:21:30 · answer #2 · answered by Rob C 3 · 0 0

boolean answer[] = new boolean[number+1];

basically you leave the first array cell blank, if you don't need it. programming languages normally start indexes with zero.

2007-09-10 12:01:13 · answer #3 · answered by rodette p 3 · 0 0

write a function like this and use it to get values from array

int get(i)nt pos)
{
return array[pos-1];
}

2007-09-09 20:37:11 · answer #4 · answered by moments 2 · 0 0

fedest.com, questions and answers