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

ICSE Computer Application BlueJ Outputs

The document contains a series of Java programming exercises with their corresponding outputs. Each question involves different programming concepts such as loops, conditionals, and string manipulation. The answers provided demonstrate the expected output for each code snippet.

Uploaded by

7emehak
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)
24 views6 pages

ICSE Computer Application BlueJ Outputs

The document contains a series of Java programming exercises with their corresponding outputs. Each question involves different programming concepts such as loops, conditionals, and string manipulation. The answers provided demonstrate the expected output for each code snippet.

Uploaded by

7emehak
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

ICSE COMPUTER APPLICATION

BLUEJ OUTPUT

Q1
class out1
{
public void main(){
int a=0;int i=4;
while(i<10)
{
a=i*2;i++;
[Link](i);
[Link](a);
}}}

Ans:
58
610
712
814
916
1018

Q2
class out2
{
public void main(){
for(int i=12;i>5;i=i-2)
{
[Link]();
[Link](i++);
}}}
Ans:
12
11
10
9
8
7
6

Q3.
for(int m=5;m<=20;m=m+5)
{
if(m%3==0)
break;
else
if(m%5==0)
[Link](m);
continue;
}
Ans:
5
10

Q4
int p=200;
while(true)
{
if(p<100)
break;
p=p-20;
}
[Link](p);
Ans: 80

Q5
int s=0,i=0;
while(i++<10)
{
s+=i;
i++;
[Link](s);}
Ans:
1
4
9
16
25
Q6.
String s="Object";
int l=[Link]();
for(int c=0;c<l;c++)
{
if([Link]([Link](c)))
[Link]([Link]([Link](c)));
else if(c%22==0)
[Link]('E');
else
[Link]([Link]([Link](c)));
}
Ans: EBJECT

Q7.
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
if((i+j)%2==0)
[Link](1);
else
[Link](0);
}
[Link]();
}
Ans:
1
01
101
0101
10101

Q8.
int i=60;
while(true)
{
if(i<=12)
break;
i=i-12;
}
[Link]("i="+i);
Ans: i=12
Q9.
int a=5; int m=0;
while(a<=7)
{
a++;
[Link]("a="+a);
m+=a;
[Link]("m="+m);}
Ans:
a=6m=6
a=7m=13
a=8m=21

Q10.

for(int a=3;a>=-1;a--)
{
for(int b=-5;b>-8;b--)
[Link]("#");
[Link]();
}
Ans:
###
###
###
###
###

Q11.

int x=5243;
while(x>0)
{
x=x/10;
[Link](x);
}
Ans:
524
52
5
0

Q12.
int x=29;
while(x>0)
{
x/=10;
[Link](x);
}
Ans:
2
0
Q13.
for(int x=-5;x<=-1;x++)
[Link](x++);
Ans:
-5
-3
-1
Q14.
for(int i=2;i<20;i=i+2)
{
if(i<10)
continue;
else
{
[Link](i);
break;
}}
Ans:
10
Q15.
int p=4, q = 36;
while(p<=q)
{
q=q/p;
[Link](q);
}
Ans:
9
2

Common questions

Powered by AI

In Q2, the for(int i=12;i>5;i=i-2) initialization starts from 12 and reduces i by 2 in each iteration. The loop prints the result of i++ which increments i after the print statement, resulting in a decrement by 1 in the sequence of printed numbers: 12, 11, 10, 9, 8, 7, 6 . The initialization and update expressions in the loop cause a mixed pattern of decrement and increment behaviors, altering the expected sequence.

In the nested loop example from Q10, the inner loop for(int b=-5;b>-8;b--) creates a sequence of three hash symbols. This is repeated four times due to the outer loop for(int a=3;a>=-1;a--), which decrements 'a' from 3 to -1. Each iteration of the outer loop prints a new line, resulting in four rows of hashes .

Loop termination is guided by the conditional check within the loop. In Q8, the while(true) loop runs indefinitely, but the condition if(i<=12) break; is assessed each iteration. The loop updates 'i' by subtracting 12 per iteration, ending when 'i' equals 12, at which point the loop terminates and 'i=12' is printed . This demonstrates a strategic use of conditions to ensure controlled termination of an otherwise infinite loop.

For loops, like those in Q2 and Q10, are often more efficient for fixed iteration counts due to the clear initialization, condition checking, and increment statement all in one line, making them concise for predictable sequences . While loops, as in Q4 and Q8, offer more flexibility handling indefinite iterations controlled by a complex condition and responsive to dynamic breaks. The choice between these depends on iteration control needs; concise predictability vs significant condition responsiveness. Efficiency consideration should examine clarity, control, and overhead needs of tasks.

In Q3 and Q14, the 'continue' statement skips the remaining statements in the loop body for the current iteration. In Q3, it is used such that if m%5==0, the value of m is printed, and subsequent code is skipped to proceed with the next iteration, thus controlling which multiples of 5 are displayed . In Q14, the 'continue' allows the loop to ignore numbers less than 10 by skipping remaining commands, continuing the loop until it breaks at i=10 .

In Q5, the sequence involves incrementing 'i' before adding it to 's', then again incrementing 'i' after adding, leading to alternate increments in the output of sums: 1, 4, 9, 16, 25. The sequence controls how the sum 's' is updated and printed . Another example is Q9 where increments and calculated sums determine subsequent 'm' values, impacting printed results: a=6m=6, a=7m=13, a=8m=21 . The order of operations within each loop impacts how and when variables are updated, affecting final outputs.

Breaking out of a loop prematurely allows bypassing remaining iterations based on specified conditions, often improving efficiency by preventing unnecessary computation. In Q3 and Q4, break statements prevent further execution under conditions m%3==0 and p<100, respectively, altering default loop completion to deliver required output results efficiently: Q3 yields '5 10' and Q4 results in '80', demonstrating application of break for desirable control and output optimization .

In Q6, the string 'Object' has its length determined by int l=s.length(). A loop iterates from 0 to l (exclusive), converting each lowercase character to uppercase using Character.toUpperCase() while handling special conditions like printing 'E' instead of uppercase 'O'. This demonstrates the iterative processing of characters based on their properties and indices to produce the modified string 'EBJECT' .

Loop invariants ensure that certain conditions are maintained throughout the execution of a loop to achieve a desired outcome. In Q4, while(true) runs indefinitely until the break condition p<100 is met. The operation p=p-20 reduces 'p' periodically, proving the invariant p>=100 is kept until the final break sets p=80 . In another example, Q11, the loop invariant ensures x remains positive until the integer division by 10 results in x=0, confirming the invariant x>0 throughout the loop execution, leading to the output sequence .

In Q6, the loop handles strings and checks conditions for converting lowercase to uppercase using Character.toUpperCase(). The loop also uses the modulo operation on the index 'c' to determine output modifications (e.g., replacing 'O' with 'E'). This involves converting data types and characters based on conditions to impact output string fully, showcasing type conversion across mixed data .

You might also like