SlideShare a Scribd company logo
1 of 8
PRACTICE EXERCISES - 1
Date: 05-FEB-2022
1) Which of the following is the correct syntax to output a message?
a) System.out.println("Hello, world!");
b) System.println.out('Hello, world!');
c) System.println("Hello, world!");
d) Out.system.println"(Hello, world!)";
e) System.println(Hello, world!);
2) What is the output produced from the following statements?
a) System.out.println(""Quotes"");
b) System.out.println("Slashes //");
c) System.out.println("How '"confounding' "" it is!");
3) What is the output from the following Java program? (Assume that a tab is
expanded into eight spaces.)
public class Letter {
public static void main(String[] args) {
System.out.println("Dear "DoubleSlash" magazine,");
System.out.println();
System.out.println("tYour publication confuses me. Is it");
System.out.println("a  slash or a //// slash?");
System.out.println("nSincerely,");
System.out.println("Susan "Suzy" Smith");
}
}
4) What series of println statements would produce the following output?
This is a test of your
knowledge of "quotes" used
in 'string literals.'
You're bound to "get it right"
if you read the section on
''quotes.''
5) What is the output produced from the following program? You may wish to
draw a structure diagram first.
public class Tricky {
public static void main(String[] args) {
message1();
message2();
System.out.println("Done with main.");
}
PRACTICE EXERCISES - 1
Date: 05-FEB-2022
public static void message1() {
System.out.println("This is message1.");
}
public static void message2() {
System.out.println("This is message2.");
message1();
System.out.println("Done with message2.");
}
}
6) What is the output produced from the following program? You may wish to
draw a structure diagram first.
public class Strange {
public static void main(String[] args) {
first();
third();
second();
third();
}
public static void first() {
System.out.println("Inside first method.");
}
public static void second() {
System.out.println("Inside second method.");
first();
}
public static void third() {
System.out.println("Inside third method.");
first();
second();
}
}
7) What is the output produced from the following program?
You may wish to draw a structure diagram first.
This is a slightly modified version of the previous problem, Strange.
public class Strange {
public static void main(String[] args) {
first();
PRACTICE EXERCISES - 1
Date: 05-FEB-2022
third();
second();
third();
}
public static void first() {
System.out.println("Inside first method.");
}
public static void second() {
System.out.println("Inside second method.");
first();
}
public static void third() {
first();
second();
System.out.println("Inside third method.");
}
}
8) What is the output produced from the following program? You may wish to
draw a structure diagram first. This is a slightly modified version of the previous
problem, Strange.
public class Strange {
public static void main(String[] args) {
second();
first();
second();
third();
}
public static void first() {
System.out.println("Inside first method.");
}
public static void second() {
System.out.println("Inside second method.");
first();
}
public static void third() {
System.out.println("Inside third method.");
first();
second();
}
}
PRACTICE EXERCISES - 1
Date: 05-FEB-2022
9) What is the output from the following Java program?
public class Confusing {
public static void method1() {
System.out.println("I am method 1.");
}
public static void method2() {
method1();
System.out.println("I am method 2.");
}
public static void method3() {
method2();
System.out.println("I am method 3.");
method1();
}
public static void main(String[] args) {
method1();
method3();
method2();
method3();
}
}
10) What is the output produced from the following program? You may wish to
draw a structure diagram first. This is a slightly modified version of the previous
problem,
public class Confusing {
public static void main(String[] args) {
method2();
method1();
method3();
method2();
}
public static void method2() {
method1();
System.out.println("I am method 2.");
}
public static void method3() {
method2();
System.out.println("I am method 3.");
method1();
}
public static void method1() {
System.out.println("I am method 1.");
}
PRACTICE EXERCISES - 1
Date: 05-FEB-2022
}
11) Which of the following are legal int literals?
a) 22
b) 1.5
c) 5.
d) -1
e) -6875309
f) '7'
g) 2.3
h) 10.0
12) What is the result of the following expression?
1 + 2 * 3 + 7 * 2 % 5
a) 1
b) 5
c) 2
d) 21
e) 11
13) Trace the evaluation of the following expressions, and give their resulting
values. Make sure to give a value of the appropriate type (such as including a .0 at
the end of a double).
a) 2 + 3 * 4 - 6
b) 14 / 7 * 2 + 30 / 5 + 1
c) (12 + 3) / 4 * 2
d) (238 % 10 + 3) % 7
e) (18 - 7) * (43 % 10)
f) 2 + 19 % 5 - (11 * (5 / 2))
g) 813 % 100 / 3 + 2.4
h) 26 % 10 % 4 * 3
i) 22 + 4 * 2
j) 23 % 8 % 3
k) 12 - 2 - 3
l) 6/2 + 7/3
m) 6 * 7 % 4
n) 3 * 4 + 2 * 3
o) 177 % 100 % 10 / 2
p) 89 % (5 + 5) % 5
q) 392 / 10 % 10 / 2
r) 8 * 2 - 7 / 4
s) 37 % 20 % 3 * 4
t) 17 % 10 / 4
PRACTICE EXERCISES - 1
Date: 05-FEB-2022
14) Which of the following choices is the correct syntax for declaring a real
number variable named 'grade' and initializing its value to 4.0?
int grade : 4.0;
4.0 = grade;
double grade = 4.0;
grade = 4;
grade = double 4.0;
15) Imagine you are writing a personal fitness program that stores the user's age,
gender, height (in feet or meters), and weight (to the nearest pound or kilogram).
Declare variables with the appropriate names and types to hold this information.
Write a complete variable declaration statement with the type, the variable name,
and a semicolon.
age ?
gender?
height ?
weight?
16) What is the value of variable x after the following code executes?
int x = 3;
x = x + 2;
x = x + x;
a) 5
b) 7
c) 3
d) 12
e) 10
17) What are the values of a, b, and c after the following code statements? (It
may help you to write down their values after each line.)
int a = 5;
int b = 10;
int c = b;
a = a + 1;
b = b - 1;
c = c + a;
a ?
b ?
c ?
PRACTICE EXERCISES - 1
Date: 05-FEB-2022
18) What are the values of first and second at the end of the following code?
int first = 8;
int second = 19;
first = first + second;
second = first - second;
first = first - second;
Output
first ________ second ___________
19) What are the values of i, j, and k after the following code statements?
int i = 2;
int j = 3;
int k = 4;
int x = i + j + k;
i = x - i - j;
j = x - j - k;
k = x - i - k;
i = ______ ; j = ________ ; k = ___________ ;
20) What is the output from the following code?
int max;
int min = 10;
max = 17 - 4 / 10;
max = max + 6;
min = max - min;
System.out.println(max * 2);
System.out.println(max + min);
System.out.println(max);
System.out.println(min);
1) Write a Java program to print the multiplications of two numbers
2) Write a Java program to print the result of the following operations.
a. -5 + 8 * 6
b. (55+9) % 9
c. 20 + -3*5 / 8
d. 5 + 15 / 3 * 2 - 8 % 3
3) Write a Java program to compute a specified formula.
Specified Formula : 4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11))
PRACTICE EXERCISES - 1
Date: 05-FEB-2022
Expected Output
2.9760461760461765
4) Write a Java program that takes three numbers as input to calculate and print the
average of the numbers.
5) Write a Java program to convert temperature from Fahrenheit to Celsius degree.
Input a degree in Fahrenheit: 212
Expected Output:
212.0 degree Fahrenheit is equal to 100.0 in Celsius
6) Write a Java program to find the value of specified expression.
a) 101 + 0) / 3
b) 3.0e-6 * 10000000.1
c) true && true
d) false && true
e) (false && false) || (true && true)
f) (false || false) && (true && true)
Expected Output:
(101 + 0) / 3)-> 33
(3.0e-6 * 10000000.1)-> 30.0000003
(true && true)-> true
(false && true)-> false
((false && false) || (true && true))-> true
(false || false) && (true && true)-> false

More Related Content

What's hot

12th information Practices multiple choice questions CBSE INDIA
12th information Practices multiple choice questions CBSE INDIA12th information Practices multiple choice questions CBSE INDIA
12th information Practices multiple choice questions CBSE INDIAHarish Gyanani
 
Exam matlab1
Exam matlab1Exam matlab1
Exam matlab1moness
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professionalIsabella789
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Intel® Software
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaanwalia Shaan
 

What's hot (13)

Parameters
ParametersParameters
Parameters
 
12th information Practices multiple choice questions CBSE INDIA
12th information Practices multiple choice questions CBSE INDIA12th information Practices multiple choice questions CBSE INDIA
12th information Practices multiple choice questions CBSE INDIA
 
Exam matlab1
Exam matlab1Exam matlab1
Exam matlab1
 
Network security CS6
Network security   CS6Network security   CS6
Network security CS6
 
Doc 20180130-wa0006
Doc 20180130-wa0006Doc 20180130-wa0006
Doc 20180130-wa0006
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
 
CMT
CMTCMT
CMT
 
Insertion Sort Code
Insertion Sort CodeInsertion Sort Code
Insertion Sort Code
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Ezmath
EzmathEzmath
Ezmath
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
 

Similar to Java Output from Practice Exercises

Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docxrosemarybdodson23141
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operatorsHarleen Sodhi
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningCarol McDonald
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...MaruMengesha
 
09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structuresjntuworld
 
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...FarhanAhmade
 
Java Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdfJava Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdfAditya Kumar
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfahmed8651
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxgitagrimston
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 
Ramco Sample Paper 2003
Ramco  Sample  Paper 2003Ramco  Sample  Paper 2003
Ramco Sample Paper 2003ncct
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IAbdul Rahman Sherzad
 
Informatics practises 12th CBSE INDIA 2012-2013 MAIN EXAM paper
Informatics practises 12th CBSE INDIA 2012-2013 MAIN EXAM paperInformatics practises 12th CBSE INDIA 2012-2013 MAIN EXAM paper
Informatics practises 12th CBSE INDIA 2012-2013 MAIN EXAM paperHarish Gyanani
 
Lecture 08 virtual machine ii
Lecture 08 virtual machine iiLecture 08 virtual machine ii
Lecture 08 virtual machine ii鍾誠 陳鍾誠
 

Similar to Java Output from Practice Exercises (20)

Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
 
09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures
 
Core Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug HuntCore Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug Hunt
 
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
 
Java Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdfJava Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdf
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docx
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
Thai
ThaiThai
Thai
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Ramco Sample Paper 2003
Ramco  Sample  Paper 2003Ramco  Sample  Paper 2003
Ramco Sample Paper 2003
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
 
Informatics practises 12th CBSE INDIA 2012-2013 MAIN EXAM paper
Informatics practises 12th CBSE INDIA 2012-2013 MAIN EXAM paperInformatics practises 12th CBSE INDIA 2012-2013 MAIN EXAM paper
Informatics practises 12th CBSE INDIA 2012-2013 MAIN EXAM paper
 
Lecture 08 virtual machine ii
Lecture 08 virtual machine iiLecture 08 virtual machine ii
Lecture 08 virtual machine ii
 
7th Semester (June-2016) Computer Science and Information Science Engineering...
7th Semester (June-2016) Computer Science and Information Science Engineering...7th Semester (June-2016) Computer Science and Information Science Engineering...
7th Semester (June-2016) Computer Science and Information Science Engineering...
 
7th Semester (June-2016) Computer Science and Information Science Engineering...
7th Semester (June-2016) Computer Science and Information Science Engineering...7th Semester (June-2016) Computer Science and Information Science Engineering...
7th Semester (June-2016) Computer Science and Information Science Engineering...
 

More from Jainul Musani

More from Jainul Musani (20)

React js t8 - inlinecss
React js   t8 - inlinecssReact js   t8 - inlinecss
React js t8 - inlinecss
 
React js t7 - forms-events
React js   t7 - forms-eventsReact js   t7 - forms-events
React js t7 - forms-events
 
React js t6 -lifecycle
React js   t6 -lifecycleReact js   t6 -lifecycle
React js t6 -lifecycle
 
React js t5 - state
React js   t5 - stateReact js   t5 - state
React js t5 - state
 
React js t4 - components
React js   t4 - componentsReact js   t4 - components
React js t4 - components
 
React js t3 - es6
React js   t3 - es6React js   t3 - es6
React js t3 - es6
 
React js t2 - jsx
React js   t2 - jsxReact js   t2 - jsx
React js t2 - jsx
 
React js t1 - introduction
React js   t1 - introductionReact js   t1 - introduction
React js t1 - introduction
 
ExpressJs Session01
ExpressJs Session01ExpressJs Session01
ExpressJs Session01
 
NodeJs Session03
NodeJs Session03NodeJs Session03
NodeJs Session03
 
NodeJs Session02
NodeJs Session02NodeJs Session02
NodeJs Session02
 
Nodejs Session01
Nodejs Session01Nodejs Session01
Nodejs Session01
 
Fundamentals of JDBC
Fundamentals of JDBCFundamentals of JDBC
Fundamentals of JDBC
 
Core Java Special
Core Java SpecialCore Java Special
Core Java Special
 
Core Java Special
Core Java SpecialCore Java Special
Core Java Special
 
Cassandra-vs-MongoDB
Cassandra-vs-MongoDBCassandra-vs-MongoDB
Cassandra-vs-MongoDB
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
 
MongoDB-SESSION02
MongoDB-SESSION02MongoDB-SESSION02
MongoDB-SESSION02
 
MongoDB-SESION01
MongoDB-SESION01MongoDB-SESION01
MongoDB-SESION01
 
4+1archi
4+1archi4+1archi
4+1archi
 

Recently uploaded

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Recently uploaded (20)

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Java Output from Practice Exercises

  • 1. PRACTICE EXERCISES - 1 Date: 05-FEB-2022 1) Which of the following is the correct syntax to output a message? a) System.out.println("Hello, world!"); b) System.println.out('Hello, world!'); c) System.println("Hello, world!"); d) Out.system.println"(Hello, world!)"; e) System.println(Hello, world!); 2) What is the output produced from the following statements? a) System.out.println(""Quotes""); b) System.out.println("Slashes //"); c) System.out.println("How '"confounding' "" it is!"); 3) What is the output from the following Java program? (Assume that a tab is expanded into eight spaces.) public class Letter { public static void main(String[] args) { System.out.println("Dear "DoubleSlash" magazine,"); System.out.println(); System.out.println("tYour publication confuses me. Is it"); System.out.println("a slash or a //// slash?"); System.out.println("nSincerely,"); System.out.println("Susan "Suzy" Smith"); } } 4) What series of println statements would produce the following output? This is a test of your knowledge of "quotes" used in 'string literals.' You're bound to "get it right" if you read the section on ''quotes.'' 5) What is the output produced from the following program? You may wish to draw a structure diagram first. public class Tricky { public static void main(String[] args) { message1(); message2(); System.out.println("Done with main."); }
  • 2. PRACTICE EXERCISES - 1 Date: 05-FEB-2022 public static void message1() { System.out.println("This is message1."); } public static void message2() { System.out.println("This is message2."); message1(); System.out.println("Done with message2."); } } 6) What is the output produced from the following program? You may wish to draw a structure diagram first. public class Strange { public static void main(String[] args) { first(); third(); second(); third(); } public static void first() { System.out.println("Inside first method."); } public static void second() { System.out.println("Inside second method."); first(); } public static void third() { System.out.println("Inside third method."); first(); second(); } } 7) What is the output produced from the following program? You may wish to draw a structure diagram first. This is a slightly modified version of the previous problem, Strange. public class Strange { public static void main(String[] args) { first();
  • 3. PRACTICE EXERCISES - 1 Date: 05-FEB-2022 third(); second(); third(); } public static void first() { System.out.println("Inside first method."); } public static void second() { System.out.println("Inside second method."); first(); } public static void third() { first(); second(); System.out.println("Inside third method."); } } 8) What is the output produced from the following program? You may wish to draw a structure diagram first. This is a slightly modified version of the previous problem, Strange. public class Strange { public static void main(String[] args) { second(); first(); second(); third(); } public static void first() { System.out.println("Inside first method."); } public static void second() { System.out.println("Inside second method."); first(); } public static void third() { System.out.println("Inside third method."); first(); second(); } }
  • 4. PRACTICE EXERCISES - 1 Date: 05-FEB-2022 9) What is the output from the following Java program? public class Confusing { public static void method1() { System.out.println("I am method 1."); } public static void method2() { method1(); System.out.println("I am method 2."); } public static void method3() { method2(); System.out.println("I am method 3."); method1(); } public static void main(String[] args) { method1(); method3(); method2(); method3(); } } 10) What is the output produced from the following program? You may wish to draw a structure diagram first. This is a slightly modified version of the previous problem, public class Confusing { public static void main(String[] args) { method2(); method1(); method3(); method2(); } public static void method2() { method1(); System.out.println("I am method 2."); } public static void method3() { method2(); System.out.println("I am method 3."); method1(); } public static void method1() { System.out.println("I am method 1."); }
  • 5. PRACTICE EXERCISES - 1 Date: 05-FEB-2022 } 11) Which of the following are legal int literals? a) 22 b) 1.5 c) 5. d) -1 e) -6875309 f) '7' g) 2.3 h) 10.0 12) What is the result of the following expression? 1 + 2 * 3 + 7 * 2 % 5 a) 1 b) 5 c) 2 d) 21 e) 11 13) Trace the evaluation of the following expressions, and give their resulting values. Make sure to give a value of the appropriate type (such as including a .0 at the end of a double). a) 2 + 3 * 4 - 6 b) 14 / 7 * 2 + 30 / 5 + 1 c) (12 + 3) / 4 * 2 d) (238 % 10 + 3) % 7 e) (18 - 7) * (43 % 10) f) 2 + 19 % 5 - (11 * (5 / 2)) g) 813 % 100 / 3 + 2.4 h) 26 % 10 % 4 * 3 i) 22 + 4 * 2 j) 23 % 8 % 3 k) 12 - 2 - 3 l) 6/2 + 7/3 m) 6 * 7 % 4 n) 3 * 4 + 2 * 3 o) 177 % 100 % 10 / 2 p) 89 % (5 + 5) % 5 q) 392 / 10 % 10 / 2 r) 8 * 2 - 7 / 4 s) 37 % 20 % 3 * 4 t) 17 % 10 / 4
  • 6. PRACTICE EXERCISES - 1 Date: 05-FEB-2022 14) Which of the following choices is the correct syntax for declaring a real number variable named 'grade' and initializing its value to 4.0? int grade : 4.0; 4.0 = grade; double grade = 4.0; grade = 4; grade = double 4.0; 15) Imagine you are writing a personal fitness program that stores the user's age, gender, height (in feet or meters), and weight (to the nearest pound or kilogram). Declare variables with the appropriate names and types to hold this information. Write a complete variable declaration statement with the type, the variable name, and a semicolon. age ? gender? height ? weight? 16) What is the value of variable x after the following code executes? int x = 3; x = x + 2; x = x + x; a) 5 b) 7 c) 3 d) 12 e) 10 17) What are the values of a, b, and c after the following code statements? (It may help you to write down their values after each line.) int a = 5; int b = 10; int c = b; a = a + 1; b = b - 1; c = c + a; a ? b ? c ?
  • 7. PRACTICE EXERCISES - 1 Date: 05-FEB-2022 18) What are the values of first and second at the end of the following code? int first = 8; int second = 19; first = first + second; second = first - second; first = first - second; Output first ________ second ___________ 19) What are the values of i, j, and k after the following code statements? int i = 2; int j = 3; int k = 4; int x = i + j + k; i = x - i - j; j = x - j - k; k = x - i - k; i = ______ ; j = ________ ; k = ___________ ; 20) What is the output from the following code? int max; int min = 10; max = 17 - 4 / 10; max = max + 6; min = max - min; System.out.println(max * 2); System.out.println(max + min); System.out.println(max); System.out.println(min); 1) Write a Java program to print the multiplications of two numbers 2) Write a Java program to print the result of the following operations. a. -5 + 8 * 6 b. (55+9) % 9 c. 20 + -3*5 / 8 d. 5 + 15 / 3 * 2 - 8 % 3 3) Write a Java program to compute a specified formula. Specified Formula : 4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11))
  • 8. PRACTICE EXERCISES - 1 Date: 05-FEB-2022 Expected Output 2.9760461760461765 4) Write a Java program that takes three numbers as input to calculate and print the average of the numbers. 5) Write a Java program to convert temperature from Fahrenheit to Celsius degree. Input a degree in Fahrenheit: 212 Expected Output: 212.0 degree Fahrenheit is equal to 100.0 in Celsius 6) Write a Java program to find the value of specified expression. a) 101 + 0) / 3 b) 3.0e-6 * 10000000.1 c) true && true d) false && true e) (false && false) || (true && true) f) (false || false) && (true && true) Expected Output: (101 + 0) / 3)-> 33 (3.0e-6 * 10000000.1)-> 30.0000003 (true && true)-> true (false && true)-> false ((false && false) || (true && true))-> true (false || false) && (true && true)-> false