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

OutputBasedonArray

The document contains a series of programming questions related to arrays in Java, including operations on integer and string arrays, output of code segments, and error identification in code. It covers topics such as array initialization, modification, and accessing elements, as well as size calculations for different data types. The questions require understanding of array manipulation and Java syntax.

Uploaded by

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

OutputBasedonArray

The document contains a series of programming questions related to arrays in Java, including operations on integer and string arrays, output of code segments, and error identification in code. It covers topics such as array initialization, modification, and accessing elements, as well as size calculations for different data types. The questions require understanding of array manipulation and Java syntax.

Uploaded by

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

Output Based Questions(Array):-

1) If int x[]={10,9,8,7,3,4}; what are the value of p and q?


p=x.length;
q=x[2]+x[5]*x[1];

2) Write the output of the following code segment:-


class Array{ void main(){ int[] a={1,2,3,4,5}; change(a);display(a):}
void change (int []ar){ for(int i=0;i<5;i+=2)ar[i]*=ar[i];}
void display (int []ar){ for(int i=0;i<5;i++)System.out.println(ar[i]);}

3) Show the value of the given array after executing the following code segment
Int a[] = {2,4,6,8,10];
a[0] +=a[4]++;
a[2]+= ++a[3];
a[4]/=a[1]++;

4) Write the output of the following code segment:-


String x[]={“Artificial Intelligence”, ”IOT”, ”Machine Learning”, ”Big Data”};
System.out.println(x[3]);
System.out.println(x.length);

5) Write the output of the following code segment:-


void display()
{
int p[]={1,11,111,1111,11111};
for(int i=(p.length-1);i>=0;i--)
System.out.println(p[i]);
}

6) Assuming int is of 4 bytes, what is the size of int arr[15]?

7) If int n [ ] = {1,2,3,5,7,9,13,16} .What are the values of ‘x’ and ‘y’


i) x = Math.pow ( n[ 4 ],n [2 ]);
ii) y = Math.sqrt ( n [5 ]+ n[7]);

8) What is the result of the following statement on the basis of given array?
int Num[ ]={3,5,10,12,8};
System.out.println(Num[2]+ “\t”+ (Num[1]*10));
System.out.println( Num[3]-5 + “\t” + Num[4-2]);

9) Show the output of the given code segment:-


char ch[ ] = {‘A’, ‘B’, ‘C’,’D’,’E’};
System.out.println( ch[0] + ch[2]);
System.out.pritnln(ch);

10) give the output of the following code segment:-


void display()
{
int arr[]={20,30,40,50,60,10};
int a=arr[1];
int b=0;
for(int ctr=0;ctr<arr.length;ctr++)
{ if(arr[ctr]<a)
{
a=arr[ctr]; b=ctr;
}
}
System.out.println(a);
System.out.println(b);
}

11) What is wrong in the following code? Explain. Also write correct form of the
following:
int u[]=new int [6];
u={2,5,6,7,8,9};

12) Find the errors if any, and correct them.


a) int ar = {2,5,7,9,4,6};
b) int m[6]={ 2,5,7,9,4,6};

13) write a valid java statement to declare and also initialize a character array of
Uppercase vowels.

14) Write a java statement to declare a single subscripted variable of 20 integers


15) Write a java statement to declare single subscripted variable of 14 real numbers
16) Write a java statement to initialize first 10 even integers in a single dimensional
array.

17) State the total size in bytes, of the array a[4] of char data type and p[4] of float
data type.
18) Write a statement to find the length of a character array named ch.

You might also like