Assignment1 Class X, 2022 23
Assignment1 Class X, 2022 23
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;
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
Q 4) Give output
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.