In: Computer Science
int[]array={90, 57, 34, 81, 59, 51, 99, 52, 78, 67}; use for numbers 1 through 4
Write code to print the given array backwards
public class Main
{
public static void main(String[] args) {
int[]array={90, 57, 34, 81, 59, 51,
99, 52, 78, 67};
System.out.println("originalarray
is : ");
print(array);
evenOdd(array);
increase(array);
average(array);
backward(array);
}
static void print(int[] list)
{
for(int i=0;i<list.length;i++)
{
System.out.print(list[i]+" ");
}
}
static void evenOdd(int[] list)
{
int[] even=new int[10];
int[] odd=new int[10];
int i1=0;
int j=0;
for(int i=0;i<list.length;i++)
{
if(list[i]%2==0)
{
even[i1++]=list[i];
}
if(list[i]%2==1)
{
odd[j++]=list[i];
}
}
System.out.println("\nodd array is : ");
print(odd);
System.out.println("\neven array is : ");
print(even);
}
static void increase(int[]
list)
{
for(int i=0;i<list.length;i++)
{
if(list[i]<50)
{
list[i]+=20;
}
}
System.out.println("\narray increase by 20 : ");
print(list);
}
static void average(int[] list)
{
float sum=0;
for(int i=0;i<list.length;i++)
{
sum=sum+list[i];
}
System.out.println("\naverage is :
"+sum/list.length);
}
static void backward(int[] list)
{
System.out.println("backward array is : ");
for(int i=list.length-1;i>=0;i--)
{
System.out.print(list[i]+" ");
}
}
}