# How do I generate an array with the output of 1,0,0,0,0.....?

How do I generate an array with the output of  1,0,0,0,0.....?
public class chap7quiz9
{
public static void main(String[] args)
{

int a[] = new int[24];
for(int i = 0; i<24;i++)
{
a =1/(1+i);
System.out.println(0);
}
}
}

today230.JPG
###### Who is Participating?

Commented:
and with the fuirst class line:

``````public class chap7quiz9
{
public static void main(String[] args)
{

float a[] = new float[24];
for(int i = 0; i<24;i++)
{
a[i] =1.0f/(1.0f+i);
System.out.println(a[i]);
}
}
}
``````
0

Commented:
Your code as you pasted it cannot compile,
a= 1/(1+i);
cannot work through compiler array cnnot be assihgned to integere or rather
integere to the arrai
0

Commented:
``````Even if you type it proably wwhta you meant
a[i]=1/(1+i)
you'll get 1 for the first element
a[0] = 1/1;
but
a[1] = 1/2;
and when you assign to int you get truncation of the
decimal part, so it wioll
a[1] = 0;

and all of the rest the same
``````
0

Commented:
In order to print something sensible
you need to declare array a as float

``````{
public static void main(String[] args)
{

float a[] = new int[24];
for(int i = 0; i<24;i++)
{
a[i] =1.0f/(1.0f+i);
System.out.println(a[i]);
}
}
}
``````

This will give you reasonable numbers
``````System.out.println(a[i]);)
``````

0

Commented:
Actually this is correct code
(forgot to chang int to float in array declaration)

``````{
public static void main(String[] args)
{

float a[] = new float[24];
for(int i = 0; i<24;i++)
{
a[i] =1.0f/(1.0f+i);
System.out.println(a[i]);
}
}
}
``````
0