SlideShare a Scribd company logo
1 of 4
Find OUTPUT of The following Code
1 int i,k;
for(i=1,k=1;i<=5;k+=i,i++)
System.out.println(i+" "+k);
2 int x=5,y;
y=++x;
System.out.println(y);
3 int a = 25;
System.out.println(a++);
System.out.println(--a);
4 int x = 5, y=6, z;
z = x++ + ++y;
System.out.println(z);
5 int m=12;
int n = m++ * 5 + --m
System.out.println(n);
6 int y=14;
int z = (++y * (y++ + 5))
7 int x = 20, y = 5, z;
z = x > y ? 100 : 50;
System.out.println(z);
8 int x =25, y;
y = ++x % 6;
System.out.println(y);
9 int a = 10, b = 5, p;
p = a++ + ++b;
System.out.println(p+” “+a+” “+b);
10 for(int x = 1; x<=15; x+=2)
System.out.println(x);
11 int x = 5;
while(x>10)
{
System.out.println(x);
x++;
}
12 int a = 5;
do
{
System.out.println(a);
a++;
}while(a<4);
13 int k=5,j=9;
k+= k++ - ++j + k;
System.out.println(“k=”+k);
System.out.println(“j=”+j);
14 double b = -15.6;
double a = Math.rint(Math.abs(b));
System.out.println(“a=”+a);
15 State the number of times loop will be
executed and the final output :
int p = 200;
While(true)
{
if(p<100)
break;
p=p-20;
}
System.out.println(p);
16 int x = 1, y = 5;
while (x<y)
{
y++;
x+=2;
}
System.out.println(x+” “+y);
17 for(int x = 1; x<=20; x++)
{
if(x % 5 == 0)
continue;
System.out.println(x);
}
18 for(int x = 1; x<=20; x++)
{
if(x % 7 == 0)
break;
System.out.println(x);
}
19 int a = 25, b = 39;
while(b>0)
{
b = b – a;
a = a – b;
}
System.out.println(a + “ “+b);
20 for(int x=0;x<=15;x+=2);
System.out.println(x);
21 int a = 5, b = 7, c;
c = ++a + b++ + --a;
System.out.println(c);
22 int x = 20, y = 25;
x = ++x + y++ + --y + --x;
System.out.println(x);
23 int n = 2,m;
m = --n *2*n;
System.out.println(m);
24 int a = 25;
int b = (++a * 4) % 25;
System.out.println(b);
25 char c = ‘A’;
short m = 26;
int n = c + m;
System.out.println(n);
26 What will be the value of following expression
if the value of m = 5 and n=20?
(m + n) > 25 ? 200 : 20;
27 Int x = 99, y = 10;
y = ++x;
System.out.println(“X:”+x+” Y:”+y);
28 double x = 0.055,y = 100.05;
System.out.println((int)(x*y));
29 int x = 10, y=15;
x = x+y;
y = x-y;
x = x-y;
System.out.println(x+ “ *** ”+y);
30 int sum = 20;
if(sum<20)
System.out.print(“Under ”);
else
System.out.println(“Over “);
System.out.println(“the limit”);
31 What will be the output, if n = 1 and if n= 2 in
the following code?
switch(n)
{
case 1:
System.out.println(“One);
break;
case 2:
System.out.println(“ Zero”);
default:
System.out.println(“Wrong input”);
}
32 int s=1,p=0;
for(int j = 1;j<=8;j++)
{
if(j<=4)
s*=j;
else
p+=j;
}
System.out.println(s+” “+p);
33 If array[]={1,9,8,5,2};
i) What is array.length?
ii) What is array[2]?
34 int x[]={1,2,3,4,5}, y ={5,4,3,2,1};
int i,j;
for(i=0,j=x.length;i<x.length;i++,j- -)
System.out.println(x[i] * y[j]);
35 String s = “Please come, let us go to play”;
System.out.println (s.substring(7,11));
System.out.println (s.lastIndexOf(‘o’));
System.out.println (s.toUpperCase());
System.out.println (s.charAt(17));
System.out.println (s.indexOf(9,’o’));
System.out.println (s.substring(0,6) +
s.substring(20,22));
36 Sting k=”WELCOME TOPPERS”
System.out.println(k.toLowerCase());
System.out.println(k.length());
System.out.println(k.indexOf(‘E’));
System.out.println(k.replace(‘O’,’A’));
System.out.println(k.substring(8));
37 String n = “Computer Knowledge.”;
String m = “Computer Application”;
System.out.println
(n.substring(0,8).concat (m.substring(9)));
System.out.println(n.endsWith(“e”);
38 System.out.println(“Four:”+(4+2));
System.out.println(“Four:”+2+2);
39 State the output of the following code
fragment, where int choice =1, x= 0;
y = 0, z=0;
switch(choice++)
{
case 2: x++; y--; z++;
break;
case 3: x+=2; y+=3; z-=3;
default: ++x; ++y; ++z;
}
System.out.println(“X=”+x+”Y =”+y+”Z=”+z);
Questions to practice to find LOGICAL and SYNTAX error in the code
1. public int getData(int num1, int num2)
{
int result = num1 + num2;
System.out.println(“Result is :” +
result);
}
2. class Add
{
public void doAddition(int x, y)
{
System.out.print(x+y);
}
}
3. if(x = 1)
k=100;
else
k = 10;
4. if ( x > y)
System.out. println(“y is greater”);
else
System.out. println(“x is greater”);
5. int i=5, j = 10
if ( (i < j) || (i=10))
System.out.println(“OK”);
System.out.println(“not OK);
6. int x=0;
while(x < 10)
System.out.println(x);
x ++;
7. for ( x = 0; x>= 10; x- -)
System.out.println(x);
8. for (i = 0, i <= 25; i ++)
System.out.println(i);
System.out.println(“the value is “;x);
9. public int add(int x,int y)
{
int z=x + y;
}
10. int a = 5 , b = 7 , c = 1;
if (a > b || b > c)
System.out.println(a + “ is greater”);
11. int a =90, b = 45, c = 45
if(a = = 90 && b = = 90 && c = = 90)
System.out.println(“Right angle
Triangle”);
12. double p =1000.00, t = 5.0, r = 10.5;
I = p * r * t / 100;
System.out.println(I);
13. double average = M1+M2+M3+M4 / 4;
14. String s = ‘computer’;
15. int l = “Good Morning”.length;
16. for (int x = 1; x < = 10 ; x++)
{
n = 1;
System.out.println(n);
n++;
}
correct the code to get 1 3 5 7 9 11 13
15 17 19 output.
17. int x, y, z;
x = 6;
y = 7;
x + y = z;
System.out.println(z);
18. int a[] = new int [10];
for( x =1 ; x<=15 ; x++)
a[x] = x * x;
19. int n = integer.ParseInt(br.readline());
20. String st = “School”;
System.out.println(st.reverse( ));
21. int x = 5, y = 8, temp;
temp = x;
x = y;
y = temp;
System.out.println(x, y, temp);
22. int x[ ] = [3,6,8,4,7,0,4,1,5];
23. int ar[ ] = [3,6,8,4,7,0,4,1,5];
System.out.println(ar.length());
Express the following in Java expression
(1-y3
)0.5
√ (x2 – x1)2
+ (y2 - y1)2
–b + (b2
-4ac)/2a
3x2
+2y [2011]
x - y
(x2
- 2y2
)3
(1 + x4
)0.25
a = (0.05 – 2y3
)/x - y
A3
+ B3
+ C3
– 3ABC
x1/3
√ l2
+ b2
x – [ y – {+ (a + b – c – d)}]
3x2
y+2yx2
( x – y)0.5
s = ut + ½at2
(a + b)n
√3 + b
√ 2as + u2
(2012)
5x * 7 – 5x
5x+2
– 5x+1
2AB + 2BC + 2CA
X2Y2 + Y2Z2 + Z2 + X2
Find the output of the following code (Java for ICSE)

More Related Content

What's hot

What's hot (20)

Complements
ComplementsComplements
Complements
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in c
 
Normal as Approximation to Binomial
Normal as Approximation to BinomialNormal as Approximation to Binomial
Normal as Approximation to Binomial
 
LR PARSE.pptx
LR PARSE.pptxLR PARSE.pptx
LR PARSE.pptx
 
fuzzy_measures.ppt
fuzzy_measures.pptfuzzy_measures.ppt
fuzzy_measures.ppt
 
Division algorithm
Division algorithmDivision algorithm
Division algorithm
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Principle of mathematical induction
Principle of mathematical inductionPrinciple of mathematical induction
Principle of mathematical induction
 
Mathematical induction
Mathematical inductionMathematical induction
Mathematical induction
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
0-1 knapsack problem
0-1 knapsack problem0-1 knapsack problem
0-1 knapsack problem
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Dld lecture module 02
Dld lecture module 02Dld lecture module 02
Dld lecture module 02
 
PPT ON NUMBER SYSTEM
PPT ON NUMBER SYSTEMPPT ON NUMBER SYSTEM
PPT ON NUMBER SYSTEM
 
Fuzzy arithmetic
Fuzzy arithmeticFuzzy arithmetic
Fuzzy arithmetic
 
5.2 primitive recursive functions
5.2 primitive recursive functions5.2 primitive recursive functions
5.2 primitive recursive functions
 

Similar to Find the output of the following code (Java for ICSE)

Similar to Find the output of the following code (Java for ICSE) (20)

Review questions and answers
Review questions and answersReview questions and answers
Review questions and answers
 
Ann
AnnAnn
Ann
 
MineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdfMineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdf
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Program for hamming code using c
Program for hamming code using cProgram for hamming code using c
Program for hamming code using c
 
03review
03review03review
03review
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
Vcs5
Vcs5Vcs5
Vcs5
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
201707 CSE110 Lecture 13
201707 CSE110 Lecture 13   201707 CSE110 Lecture 13
201707 CSE110 Lecture 13
 
ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.ppt
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
Los dskn
Los dsknLos dskn
Los dskn
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 

Recently uploaded

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Recently uploaded (20)

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

Find the output of the following code (Java for ICSE)

  • 1. Find OUTPUT of The following Code 1 int i,k; for(i=1,k=1;i<=5;k+=i,i++) System.out.println(i+" "+k); 2 int x=5,y; y=++x; System.out.println(y); 3 int a = 25; System.out.println(a++); System.out.println(--a); 4 int x = 5, y=6, z; z = x++ + ++y; System.out.println(z); 5 int m=12; int n = m++ * 5 + --m System.out.println(n); 6 int y=14; int z = (++y * (y++ + 5)) 7 int x = 20, y = 5, z; z = x > y ? 100 : 50; System.out.println(z); 8 int x =25, y; y = ++x % 6; System.out.println(y); 9 int a = 10, b = 5, p; p = a++ + ++b; System.out.println(p+” “+a+” “+b); 10 for(int x = 1; x<=15; x+=2) System.out.println(x); 11 int x = 5; while(x>10) { System.out.println(x); x++; } 12 int a = 5; do { System.out.println(a); a++; }while(a<4); 13 int k=5,j=9; k+= k++ - ++j + k; System.out.println(“k=”+k); System.out.println(“j=”+j); 14 double b = -15.6; double a = Math.rint(Math.abs(b)); System.out.println(“a=”+a); 15 State the number of times loop will be executed and the final output : int p = 200; While(true) { if(p<100) break; p=p-20; } System.out.println(p); 16 int x = 1, y = 5; while (x<y) { y++; x+=2; } System.out.println(x+” “+y); 17 for(int x = 1; x<=20; x++) { if(x % 5 == 0) continue; System.out.println(x); } 18 for(int x = 1; x<=20; x++) { if(x % 7 == 0) break; System.out.println(x); } 19 int a = 25, b = 39; while(b>0) { b = b – a; a = a – b; } System.out.println(a + “ “+b); 20 for(int x=0;x<=15;x+=2); System.out.println(x); 21 int a = 5, b = 7, c; c = ++a + b++ + --a; System.out.println(c); 22 int x = 20, y = 25; x = ++x + y++ + --y + --x; System.out.println(x); 23 int n = 2,m; m = --n *2*n; System.out.println(m); 24 int a = 25; int b = (++a * 4) % 25; System.out.println(b); 25 char c = ‘A’; short m = 26; int n = c + m; System.out.println(n); 26 What will be the value of following expression if the value of m = 5 and n=20? (m + n) > 25 ? 200 : 20;
  • 2. 27 Int x = 99, y = 10; y = ++x; System.out.println(“X:”+x+” Y:”+y); 28 double x = 0.055,y = 100.05; System.out.println((int)(x*y)); 29 int x = 10, y=15; x = x+y; y = x-y; x = x-y; System.out.println(x+ “ *** ”+y); 30 int sum = 20; if(sum<20) System.out.print(“Under ”); else System.out.println(“Over “); System.out.println(“the limit”); 31 What will be the output, if n = 1 and if n= 2 in the following code? switch(n) { case 1: System.out.println(“One); break; case 2: System.out.println(“ Zero”); default: System.out.println(“Wrong input”); } 32 int s=1,p=0; for(int j = 1;j<=8;j++) { if(j<=4) s*=j; else p+=j; } System.out.println(s+” “+p); 33 If array[]={1,9,8,5,2}; i) What is array.length? ii) What is array[2]? 34 int x[]={1,2,3,4,5}, y ={5,4,3,2,1}; int i,j; for(i=0,j=x.length;i<x.length;i++,j- -) System.out.println(x[i] * y[j]); 35 String s = “Please come, let us go to play”; System.out.println (s.substring(7,11)); System.out.println (s.lastIndexOf(‘o’)); System.out.println (s.toUpperCase()); System.out.println (s.charAt(17)); System.out.println (s.indexOf(9,’o’)); System.out.println (s.substring(0,6) + s.substring(20,22)); 36 Sting k=”WELCOME TOPPERS” System.out.println(k.toLowerCase()); System.out.println(k.length()); System.out.println(k.indexOf(‘E’)); System.out.println(k.replace(‘O’,’A’)); System.out.println(k.substring(8)); 37 String n = “Computer Knowledge.”; String m = “Computer Application”; System.out.println (n.substring(0,8).concat (m.substring(9))); System.out.println(n.endsWith(“e”); 38 System.out.println(“Four:”+(4+2)); System.out.println(“Four:”+2+2); 39 State the output of the following code fragment, where int choice =1, x= 0; y = 0, z=0; switch(choice++) { case 2: x++; y--; z++; break; case 3: x+=2; y+=3; z-=3; default: ++x; ++y; ++z; } System.out.println(“X=”+x+”Y =”+y+”Z=”+z); Questions to practice to find LOGICAL and SYNTAX error in the code 1. public int getData(int num1, int num2) { int result = num1 + num2; System.out.println(“Result is :” + result); } 2. class Add { public void doAddition(int x, y) { System.out.print(x+y); } } 3. if(x = 1) k=100; else k = 10; 4. if ( x > y) System.out. println(“y is greater”); else System.out. println(“x is greater”); 5. int i=5, j = 10 if ( (i < j) || (i=10)) System.out.println(“OK”); System.out.println(“not OK); 6. int x=0; while(x < 10) System.out.println(x); x ++; 7. for ( x = 0; x>= 10; x- -) System.out.println(x); 8. for (i = 0, i <= 25; i ++) System.out.println(i); System.out.println(“the value is “;x);
  • 3. 9. public int add(int x,int y) { int z=x + y; } 10. int a = 5 , b = 7 , c = 1; if (a > b || b > c) System.out.println(a + “ is greater”); 11. int a =90, b = 45, c = 45 if(a = = 90 && b = = 90 && c = = 90) System.out.println(“Right angle Triangle”); 12. double p =1000.00, t = 5.0, r = 10.5; I = p * r * t / 100; System.out.println(I); 13. double average = M1+M2+M3+M4 / 4; 14. String s = ‘computer’; 15. int l = “Good Morning”.length; 16. for (int x = 1; x < = 10 ; x++) { n = 1; System.out.println(n); n++; } correct the code to get 1 3 5 7 9 11 13 15 17 19 output. 17. int x, y, z; x = 6; y = 7; x + y = z; System.out.println(z); 18. int a[] = new int [10]; for( x =1 ; x<=15 ; x++) a[x] = x * x; 19. int n = integer.ParseInt(br.readline()); 20. String st = “School”; System.out.println(st.reverse( )); 21. int x = 5, y = 8, temp; temp = x; x = y; y = temp; System.out.println(x, y, temp); 22. int x[ ] = [3,6,8,4,7,0,4,1,5]; 23. int ar[ ] = [3,6,8,4,7,0,4,1,5]; System.out.println(ar.length()); Express the following in Java expression (1-y3 )0.5 √ (x2 – x1)2 + (y2 - y1)2 –b + (b2 -4ac)/2a 3x2 +2y [2011] x - y (x2 - 2y2 )3 (1 + x4 )0.25 a = (0.05 – 2y3 )/x - y A3 + B3 + C3 – 3ABC x1/3 √ l2 + b2 x – [ y – {+ (a + b – c – d)}] 3x2 y+2yx2 ( x – y)0.5 s = ut + ½at2 (a + b)n √3 + b √ 2as + u2 (2012) 5x * 7 – 5x 5x+2 – 5x+1 2AB + 2BC + 2CA X2Y2 + Y2Z2 + Z2 + X2