Professional Documents
Culture Documents
Practice Worksheet 7
Practice Worksheet 7
1. 2. 3.
public static void main()
{ void printArray () public static void main()
double time[]={12.0, 1.30, 2.15, 2.45, { {
3.15,9.0}; int a[]={0, 5,10, 20,17}; int a[]={5,7,3,11,6,};
int i=1; int i=1;
System.out.println(a); do
while (time[i]) System.out.println(a[7]); {
{ System.out.println(a[i]);
System.out.println(time [++i]); } i++;
} } while(a[i]<=10);
} }
4. 5.
public static void main() public static void main()
{ {
String a[]={“Raj”, ”Rahul”,” Ashish”}; int a[]={2, 7 , 15, 17, 26 ,
20, 44};
for (int i=1; i<=2; i++) int i=1;
System.out.println(i + a[i] + a[i].length()); while (a[i]<20)
} {
System.out.println(a[++i]);
}
}
1. 2. 3.
public static void main() public static void main() public static void main()
{ { {
int a[10,5,3,6,7]; // int a[][]=new int[3,3]; int a[]={10,20,30,40}; //
initializing array; int i,j; initializing array;
System.out.println(a.length()); for (i=1; i<=3; i++) display(a[]);
chkArray(a[]); System.out.println(a[i][j]) }
} }
public void display(int a)
public void chkArray() {
{ int i;
// …. Assume code written here for (i=0; i<=a.length; i++)
} System.out.println(a[i]);
}
3. Which of the following array declarations are valid / invalid, State reasons – [4]
a. int []marks=new int[];
b. byte age[]=new age[100];
c. boolean status[]=new Boolean[];
d. int a[][]=new int[3,3];
b. Declare an array which can be used to store grades of 10 students inputted by the user.
c. To declare and intialise an array with height of 3 students given as 175.5, 168.8, 171.4.
5. Consider the following declaration and answer the questions given below
char a[]={‘a’ ,’b’ , ’c’ , ’d’ , ’e’, ’f’ };