0% found this document useful (0 votes)
115 views4 pages

Assignment1 Class X, 2022 23

This document contains 5 questions related to Java programming concepts like prefix and postfix operators, loops, jump statements, ternary operator etc. Question 1 has 3 parts asking for the output of code snippets using prefix, postfix operators. Question 2 has 2 parts with code using loops, continue, break statements. Question 3 has 5 parts containing code using while, for loops, break, continue statements. Question 4 and 5 have code snippets using ternary operator. The student is asked to solve these questions writing the output and working in their assignment copy.
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)
115 views4 pages

Assignment1 Class X, 2022 23

This document contains 5 questions related to Java programming concepts like prefix and postfix operators, loops, jump statements, ternary operator etc. Question 1 has 3 parts asking for the output of code snippets using prefix, postfix operators. Question 2 has 2 parts with code using loops, continue, break statements. Question 3 has 5 parts containing code using while, for loops, break, continue statements. Question 4 and 5 have code snippets using ternary operator. The student is asked to solve these questions writing the output and working in their assignment copy.
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/ 4

Assignment -1 CLASS-X A & B (2022-23)

Questions based on prefix and postfix


Part-I
Q 1) Give output
i) int r=10,s=0,t=25; t=r++ + ++r/++s+ ++r; r=? , s= ? , t=?

ii) int x=10,y=5,z=20; z*=(x++)/2+(++y)%3; x=?, y=? , z=?

iii) int k=15,m=5,n=1; k+=+m +n-- + ++k + m/2; k=? ,m=? , n=?

Q 2) Give output
int a=20 ,b=40,c=60;
i) a+= (++b / 3 )+ ( c+=2 /3 ) ; a=?
ii) a=++b%4+c++/4 +a*5; a=?
iii) a=c+(a++ + ++b)/2; a=?

Q 3) Give output
int x=4; float y=8.0F; double R,z=10.0;

i) R=(x+y)%3 + (int)(z/4); R=?


ii) R=(int)(x+y+z)%7+x; R=?
iii) R=z*z/++x+y/8; R =?

Questions based on for loops, while loops, jump statements & ternary operator
Part-II
Q 1) Give output of following program segments:

a)
int a,c;
for(a=20;a>=0;a-=4);
System.out.println(a);
System.out.println(Math.sqrt(a));

PTO
1
b)
int a=30;char c='A';
while(a++<33)
System.out.print(c++ +" ");
System.out.print(c+""+a);

c)
int x=10;boolean ch=false;
while(!ch)
{
x-=2;
System.out.print(x+" ");
if(x==4)
ch=true;
}
System.out.print("\n"+x);

d)
int x='A';
while(x++%3>0)
System.out.print(x);
System.out.print((char)x);

e)
int x,y;
for(x=20,y=1;y<=x;x-=5,y+=4 )
System.out.println(x*y);
System.out.println(x+y);

Q 2) Give the output of the following program segment and also mention how many times
the loop is executed:
a)
for (int m=25; m<=35; m+=5)
{
if (m%7==0)
break;
else if (m%5==0)
System.out.println(m);
continue;
}

PTO

2
b)
int a,b;
for (a=34,b=5;a<=50;a+=6)
{
if (a%b==0)
continue;
System.out.print(a+" ");
}
System.out.print(a+" ");

c)
int a=10;
while(a<=60)
{
System.out.print(a+=10);
if(a%4==0)
continue;
break;
}
System.out.print("\n#");

d)
int a=35,c=20;
while(++c<=a)
{
System.out.print(c+=5);
if(a%2!=0)
System.out.print("*");
continue;
}

e)
int p,q;
for(p=2,q=20;p<5;p++)
{
System.out.println((int)Math.pow(q,p));
if(q/p==4)
break;
p++;
}

PTO

3
Q 3) Give output

public void main()


{
int n;
boolean r=false;
if(r)
n=(r ? 500 : 600);
else
n=( !r ? 5000 : 6000);
System.out.println(n);
}

Q 4) Give output

public void main()


{
int n;
boolean r=false;
if(!r)
n=(!r ? 30 : 20);
else
n=( r ? 300 : 200);
System.out.println(n);
}

Q 5) Give output
public void main()
{
int n;
boolean r=!false;
if(!r)
n=(r ? 400 : 700);
else
n=( !r ? 8000 : 3000);
System.out.println(n);
}

Note : Solve and write answers(with working) of above questions in your Board Assignment Copy.

You might also like