0% found this document useful (0 votes)
35 views

Java Program-Predict The Output-Iteration - New

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)
35 views

Java Program-Predict The Output-Iteration - New

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

1.

Write the output of the following codes:


(a) int j = 0, result = 1;
for(j = 3; j < = 5; j++)
{
result = j;
for(g = 5; g >=3; g - -)
{
result = result * g;
}
System.out.print(“ \ n Result is “ + result);
}
System.out.print (“ \ n Out Of The Loop Value of (j,g) are “ + j + “ , “ + g);

(b) int cnt = 10;


while (cnt > = 1)
{
System.out.print(cnt - - + “ “)
cnt - = 2;
}

(c) int cnt = 10;


for (int j = 1; j < = cnt; j++)
{
System.out.print (j + “ “);
if ( j % 3 = = 0)
j++;
}

(d) int cnt = 10;


for ( int j = 1, k = 1; j < = cnt; j++, k++)
{
System.out.print (k + “ “ );
if ( j % 2 = = 0)
{
k = j + 1;
System.out.println( );
}
}

(e ) for (int j = 1; j < = cnt; j++)


{
System.out.print(j + “ \ t”);
if (k = = j && j ! = cnt)
{
j = 0;
k++;
System.out.println ( );
} }

(f) double dbl = 10.5;


for (double d = 1; d <= dbl; d+= 0.5 )
{
if (d % 2.5 == 0)
{
System.out.print (d + “ \ t”);
} }
(g) double db2 = 123.45;
int p = 0;
double d1 = db2;
while (db2 – (int) db2 > 0)
{
db2 = db2 * 10;
p - -;
System.out.println (“ ## “ + db2);
}
System.out.println (“ \n Finally :” + db1
+ “ is \ t” + db2 + “ x 10^”
+ p);

(h) int b = 56478;


int b2 = b;
int r = 0;
while (b2 ! = 0)
{
System.out.println (b2 + “ \t” + r);
r = r * 10 + (b2 % 10 );
b2 = b2 / 10;
}

2. In the following code snippets, identify if there is any error or not:


a) double d1 = 19.2, d2 = 42.5;
int t1 = d1;
System.out.print (“ d1 = “ + d1 + “ \t and t1 =” + t1);

b) boolean pm= true;


int n = 77;
for (int j = 2; j < = n/2; j++)
{
if (n % j = = 0)
pm = false;
break;
}
c) for(int j = 1; j < = n; j++)
{
int c = 0;
if(n % j = = 0)
c++;
}
d) System.out.print(“Enter a char.....”);
vh = sca.next Line( ).charAt (0);
System.out.print(“vh =” + vh);

e) //input a,b
d = a/b;
r = a%b;
System.out.print(“Quotient =” +d+ “Remainder =” +r );

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy