Professional Documents
Culture Documents
Assignment 1
Assignment 1
Assignment 1
a)
public class Class1
{
public static void main(String[] args)
{
int []b={2,5,6,3,8,5};
for(int i=1;i<6;i++) //adding 2 with elements in array, but
exclude first element.
b[i]=b[i]+2; //finally b=[2,7,8,5,10,7]
for(int i=5;i>0;i--) //access the fifth element ,then print
the array reverse order
System.out.println(b[i]); //[7,10,5,8,7]
//here also avoid first element
}
}
output
b)
{
public static void main(String[] args)
{
int a[][]=new int[2][3];
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=(i+j)*(i-j);
/* a[0][0]=0
a[0][1]=-1
a[0][2]=-4
a[1][0]=1
a[1][1]=0
a[1][2]=-3
*/
}
}
}
}
output
c) the output of the c part is error, Some exception will occured. The output is as follows.
This is because,
2)
a) ama
b) //empty space
c)Cd
d)-1 //since there is no matched char 'M' present
e) SARAKhalid
OUTPUT
3)
OUTPUT
4)
OUTPUT
5) options B,C are valid
B) float average[];
C) double[] marks;
6)
Option D and E are correct