how to create array in java
Answers
Answer:
first step
Explanation:
open java second step settins and array
Just declare a variable followed by [ ] and assign value to it .
Example :-class arry
{
public static void main()
{
int a[]= {1,2,3,4,6,7,8,9,5,20,19,18,17,16,15,14,13,12,11,10};
int length = a.length;
int temp,sum=0;
for(int i=0; i<length; i++)
{
for(int j= 0; j<length-1-i; j++)
{
if(a[j]>a[j+1])
{
temp= a[j];
a[j]= a[j+1];
a[j+1]= temp;
}
}
}
System.out.println("LARGEST NUMBER = " + a[length-1]);
System.out.println("Smallest NUMBER = " + a[0]);
for(int i=0; i<length ; i++)
{
sum+=a[i];
}
System.out.println("SUM = " + sum);
}
}