Array Program

Create an array of size 10. Automatically fill the array with the factorial of number between 1 to 10, and then display the content of array.
 public class ques3 
public static void main() 
 int i,f=1;
 int x[]=new int[10]; 
 for(i=0;i<10;i++) 
 {
 f=f*(i+1); x[i]=f; 
 } 
 for(i=0;i<10;i++) 
 System.out.println(x[i]);
 }
 } 
Create three arrays A, B and C both of size 5. Accept numbers in two arrays A and B. Fill all the elements of array C with the sum of numbers present in appropriate element of array A and B.
public class ques4
 { 
public static void main()
 { 
 int i; int a[]={1,2,3,4,5}; 
 int b[]={6,7,8,9,10}; 
 int c[]=new int[5]; 
 for(i=0;i<5;i++)
 c[i]=a[i]+b[i];
 for(i=0;i<5;i++)
 System.out.println(c[i]);
 } 
}

No comments:

Post a Comment

what is chain constructor in java

  In Java, chain constructor refers to a technique where one constructor calls another constructor within the same class. This is achieved b...