0% found this document useful (0 votes)
12 views6 pages

Array Output2020

This document contains 14 questions and answers related to arrays in Java. The questions cover topics like initializing and accessing array elements, nested for loops to iterate through arrays, array operations like addition and multiplication, 2D arrays, and calculating sums of array elements. The answers provided are the outputs of the code snippets.

Uploaded by

avyuktnalla114
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

Array Output2020

This document contains 14 questions and answers related to arrays in Java. The questions cover topics like initializing and accessing array elements, nested for loops to iterate through arrays, array operations like addition and multiplication, 2D arrays, and calculating sums of array elements. The answers provided are the outputs of the code snippets.

Uploaded by

avyuktnalla114
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

COMPUTER APPLICATION

OUTPUT QUESTION WITH ANSWER


CHAPTER: ARRAY

Q1
class a1
{
public void main()
{
int a []=new int [5];
a[0]=15; a[2]=17; a[1]=3;a[4]=2;a[3]=78;
a[2]=22; a[0]=51; a[4]=27;
for (int m=0;m<4; m++)
System.out.println(a[m]);
}}
Ans:
51
3
22
78

Q2
int s; s=0;
int a[] = {18, 16, 14, 12};
for(int m = 3;m>=0;m--)
{s=a[m]-a[3-m];
System.out.println(s);
}
Ans:
-6
-2
2
6

1
Q3
int a[]={20, 19, 18, 17, 16, 11, 12, 13, 14, 15};
for(int m=0;m<a.length;m++)
System.out.println(a[m%3]);

Ans:
20
19
18
20
19
18
20
19
18
20

Q4.
int a[]={5, 4, 3, 2, 1};
for(int m=a.length-1;m>=0;m--)
System.out.println(a[m]*2);
Ans:

2
4
6
8
10

2
Q5

int a[]={100, 200, 300, 400, 500};


int s=0;
for(int m=a.length-1;m>=0;m--)
{System.out.println(a[m]);
s+=a[m]; }
System.out.println(s);

Ans:
500
400
300
200
100
1500

Q6.
String s[] = {"nasir", "shabina", "shaikh"};
for(int i=0; i<=2; i++)

System.out.println(s[i].charAt(i));
Ans:
n
h
a

Q7. int a[]={5,8,7,3,2};


a[1]=a[3];
a[2]=a[4];
a[3]=a[1]+a[2];
for(int i=0;i<5;i++)
System.out.println(a[i]+",");
3
ANS:
5,
3,
2,
5,
2,

Q8.
int a[ ]={17,10,9,18,7};
a[4]=a[3]; a[4]=a[1]-a[2];
System.out.print(a[4]+" "+a[3]);

ANS: 1 18
Q9. int a[]=new int[5];
int i;
for(i=0;i<5;i++)
a[i]=3*i;
for(i=0;i<5;i++)
System.out.println( a[i]);
ANS
0
3
6
9
12

Q10.
int h[][]={{1,2,3},{5,6,7},{8,9,4}};
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
4
if(i==j || i+j==2)
System.out.print(h[i][j]+" ");
else
System.out.println();
}
}
Ans
1
3
6
8
4

Q11.
int a[]={100,9,45,99,88};
int s=0;
for(int i=0;i<a.length;i++)
{
if(a[i]%2==0)
s=s+a[i];
}
System.out.println(s);

Ans: 188
Q12.
char ch[]={'a','b','c'};
String s1=new String(ch);
String s2=new String(s1);
System.out.println(s1);
System.out.println(s2);
Ans:
abc
abc

5
Q13.
int i,j,s;s=0;
int m[][]={{1,2,4,5},{4,7,17,2}};
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
s=s+m[i][j];
}
}System.out.println("sum of numbers :"+s);
Ans: 42

Q14.
int a,b=0;
int c[]={1,2,3,4,5,6,7,8,9,10};
for(a=0;a<10;a++)
{
if(a%2==0)
b+=c[a];
}
System.out.print(b);
Ans: 25

You might also like