You are on page 1of 4

Home Work #2

Task#1 Writing on the console


In this task, you’ll practice to print on the console.

Print the following in Java


 Your First name
 Your Last name
 Your University name
 Your Department name
 Your Degree name
 Your CGPA
 Your Email address

Instructions
1. Create a program with the filename PrintConsole.java.
Note: filename and class name must be the same.
2. Write the print statements to display output.

Task #2: Writing on the console

In this task, you’ll write a simple program which will generate the following output.

Output
Programming is great fun! I can’t get enough of it.

Instructions
1. Create a program with the filename HelloProgramming.java.
Note: filename and class name must be the same.
2. Write the print statements to display output.
Note that both messages are on separate lines.
Task #3: Writing on the console using Escape Sequences
In this task, you will write a program which will generate the following output using escape
sequences.

Sample Output
School of Electrical Engineering and Computer Science (SEAS) offers:

1. BS Computer Science
2. BS Software Engineering
3. BS Data Science
4. BS Computational Mathematics
5. Associate Degree in Computer Science
Instructions
1. Create a program with the filename EscapeSequences.java.
Note: filename and class name must be the same.
2. Write the print statements with proper escape sequence to display output.

Task #4: Writing on the console using Escape Sequences


In this task, you are being asked to write a program to generate the following output with the
help of escape sequences:

Sample Output
Following are our most enrolled elective courses:
Web Development
Web Application Development
Mobile Computing
Android Application Development
Instructions
1. Create a program with the filename NewAndTab.java.
Note: filename and class name must be the same.
2. Write the print statements with proper escape sequences to display output.

Task #5: Drawing a flowchart from word problem


In this task, you are being asked to understand the given statement and draw the flowchart.

Babar bought a camera for Rs. 370 and sold the same camera for Rs. 458. Now, Babar wants to find if he has
made a profit or loss.

Draw a flowchart for above given problem.

Task #6: Drawing a flowchart


In this task, you are being asked to draw a flowchart.

Draw a flowchart to find largest of two numbers.


Task #1: Understanding Logical Operators
Following table explains the meaning of different logical operators available in Java.

Operator Meaning Effect


&& AND Connects two boolean expressions into one. Both expressions must be
true for the overall expression to be true.

|| OR Connects two boolean expressions into one. One or both expressions


must be true for the overall expression to be true. It is only necessary
for one to be true, and it does not matter which one.

! NOT The ! operator reverses the truth of a boolean expression. If it is applied


to an expression that is true, the operator returns false. If it is applied
to an expression that is false, the operator returns true.

We know that a Boolean Expression’s result is either true or false. The truth table for all three operators is
shown below.

Boolean Boolean BE1 && BE2 BE1 || BE2 !(BE1)


Expression 1 Expression 2
(BE1) (BE2)
true true true true false

true false false true false

false true false true true

false false false false true

Now, assume that a = 2, b = 4 and c = 6. Determine the value of each expression given below as true or
false.
1. a == 4 || b > 2
2. c >= 6 && a > 3
3. b != 1 && c != 3
4. a >= -1 || a <= b
5. !( a > 2 )
Task #1: Writing a while loop
In this task, you are being asked to write a loop in Java.

Write while loops that prints:

i. Numbers from 1 to 100


ii. Numbers from 100 to 1
iii. Number from 0 to 50 with an increment of 5 i.e. (0 5 10 15. . . 50)
iv. Your name 5 times

1. Create a program called WhileLoopSeriesLab7.java.


2. Correctly display appropriate messages.

You might also like