Sol_OOP I(Python+Java) (1)
Sol_OOP I(Python+Java) (1)
DRONA FOUNDATION
BVOC - IT
Sr No INDEX
1 Modules in Python
1.1 Modules Python Introduction
1.2 Modules Python Random
Modules Python Namespaces
1.3
1.4 Modules Python Decimals
1.5 Modules Python Files and Scope
2 CREATING DICTIONARIES
2.1 Introduction to Python Dictionaries
2.2 Make a Dictionary
2.3 Invalid Keys
2.4 Empty Dictionary
Add A Key
2.5
2.6 Add Multiple Keys
2.7 Overwrite Values
2.8 Dict Comprehensions
2.9 Review
2 Quiz
3 USING DICTIONARIES
3.2 Get A Key
3.3 Get an Invalid Key
3.4 Safely Get a Key
3.5 Delete a Key
3.6 Get All Keys
3.7 Get All Values
3.8 Get All Items
3.9 Review
1 Project : Scrabble
3 Quiz
5 INTRODUCTION TO CLASSES
5.1 Types
5.2 Class
5.3 Instantiation
5.4 Object-Oriented Programming
5.5 Class Variables
5.6 Methods
5.7 Methods with Arguments
5.8 Constructors
5.9 Instance Variables
5.1 Attribute Functions
5.11 Self
5.3 Everything is an Object
5.13 String Representation
5.5 Review
5 Quiz
3 Project : Basta Fazoolin’
JAVA
1 HELLO WORLD
1.2 Hello Java File!
1.3 Print Statements
2
1.4 Commenting Code
1.5 Semicolons and Whitespace
1.6 Compilation: Catching Errors
1.8 Java Review: Putting It All Together
1 Quiz
1 Project : Planting a Tree
2 VARIABLES
2.1 Introduction
2.2 Ints
2.3 Doubles
2.4 Booleans
2.5 Char
2.6 String
2.7 Static Checking
2.8 Naming
2.9 Review
2 Quiz
2 Project : Java Variables : Mad Libs
3 Manipulating Variables
3.1 Introduction
3.2 Addition and Subtraction
3.3 Multiplication and Division
3.4 Modulo
3.5 Compound Assignment Operators
3.6 Order of Operations
3.7 Greater Than and Less Than
3.8 Equals and Not Equals
3.9 Greater/Less Than or Equal To
3.10 .equals()
3.11 String Concatenation
3.12 final Keyword
3.13 Review
3 Quiz
3 Project : Math Magic
3
1. Modules in Python
1.1 Modules Python Introduction Instructions
# Import datetime from datetime below:
from datetime import datetime
current_time = datetime.now()
print(current_time)
4
print(randomer_number)
import codecademylib3_seaborn
import random
numbers_b = random.sample(range(100), 3)
plt.plot(numbers_a, numbers_b)
plt.show()
5
# Fix the floating point math below:
two_decimal_points = Decimal('0.2') + Decimal('0.69')
print(two_decimal_points)
6
2.CREATING DICTIONARIES
2.1 Introduction to Python Dictionaries Instructions
sensors = {"living room": 21, "kitchen": 23, "bedroom": 20, "pantry": 22}
num_cameras = {"backyard": 6, "garage": 2, "driveway": 1}
print(sensors)
7
animals_in_zoo['monkeys'] = 3
animals_in_zoo['dinosaurs'] = 0
print(animals_in_zoo)
8
songs = ["Like a Rolling Stone", "Satisfaction", "Imagine", "What's Going On",
"Respect", "Good Vibrations"]
playcounts = [78, 29, 44, 21, 89, 5]
plays["Respect"] = 94
plays["Purple Haze"] = 1
print(library)
__________________________________________
2. Quiz
inventory["invisible knife"] = 40
inventory["mithril shield"] = 25
a) {"iron spear": 3, "invisible knife": 70, "needle of ambition": 1, "stone glove":
20, "mithril shield": 25}
b) {"iron spear": 3, "invisible knife": 40, "needle of ambition": 1, "stone
glove": 20, "mithril shield": 25}
9
c) {"iron spear": 3, "invisible knife": 70, "needle of ambition": 1, "stone glove":
20}
d) {"iron spear": 3, "invisible knife": 30, "needle of ambition": 1, "stone glove":
20, "invisible knife": 40, "mithril shield": 25}
3. Which of these dictionaries has integers as the keys and strings as the values?
a) zipcodes = {"Alabama":35801,"Alaska":99501, "Oregon":97201,
"Vermont":05751, "New Jersey":07039}
b) zipcodes = {35801: "Alabama", "No Value": "N/A", "APO": "Overseas"}
c) zipcodes = {35801: "Alabama", 99501: "Alaska", 97201: "Oregon", 05751:
"Vermont", 07039: "New Jersey"}
d) zipcodes = {35801: ["Huntsville", "Montgomery"], 99501: ["Anchorage"],
97201: ["Portland", "Salem"], 05751: ["Burlington", "Montpelier",
"Rutland"], 07039: ["Hoboken"]}
print(room_dict)
10
b) [("executive", 7), ("hopper", 20), ("lovelace", 6), ("pod", 2), ("snooze
booth", 1)}
c) ["executive", 7, "hopper", 20, "lovelace", 6, "pod", 2, "snooze booth", 1]
d) {"executive": 7, "hopper": 20, "lovelace": 6, "pod": 2, "snooze booth": 1}
11
3.USING DICTIONARIES
3.2 Get A Key Instructions
print(zodiac_elements['earth'])
print(zodiac_elements['fire'])
if "energy" in zodiac_elements:
print(zodiac_elements["energy"])
12
user_ids = {"teraCoder": 10019, "pythonGuy": 182921, "samTheJavaMaam":
3313, "lyleLoop": 3931, "keysmithKeith": 39384}
print(tc_id)
print(stack_id)
print(available_items)
print(health_points)
13
num_exercises = {"functions": 1, "syntax": 13, "control flow": 15, "loops": 22,
"lists": 19, "classes": 18, "dictionaries": 18}
users = user_ids.keys()
lessons = num_exercises.keys()
print(users)
print(lessons)
total_exercises = 0
14
print("Women make up " + str(percentage) + " percent of " + occupation + "s.")
spread = {}
spread["past"] = tarot.pop(13)
spread["present"] = tarot.pop(22)
spread["future"] = tarot.pop(1)
__________________________________________
Project-1
Scrabble
15
# Step 1
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 1, 1, 1, 1, 1, 4, 4, 8, 4, 1]
# Step 2
letter_to_points[" "] = 0
# Step 3-6
def score_word(word):
point_total = 0
for letter in word:
point_total += letter_to_points.get(letter, 0)
return point_total
# Step 7-8
brownie_points = score_word("BROWNIE")
print(brownie_points)
# Step 9
player_to_words = {
"player1": ["wordNerd", "Lexi", "Con", "Prof", "Reader"],
"BLUE": ["EARTH", "ERASER", "ZAP"],
16
"TENNIS": ["EYES", "BELLY", "COMA"],
"EXIT": ["MACHINE", "HUSKY", "PERIOD"]
}
# Step 1
player_to_points = {}
# Step 11-5
for player, words in player_to_words.items():
player_points = 0
for word in words:
player_points += score_word(word)
player_to_points[player] = player_points
print(player_to_points)
__________________________________________
3. Quiz
17
c) KeyError
d) ["veggie burger", "salad", "soda"]
18
b) 30
c) 1
d) ("stone glove", 20)
a) 'No Value'
b) {223842: 'Teddy Bear', 872921: 'Concert Tickets', 320291: 'Gift Basket',
4333: 'Necklace', 298787: 'Pasta Maker', 561721: 'No Value'}
c) KeyError
d) {223842: 'Teddy Bear', 872921: 'Concert Tickets', 320291: 'Gift Basket',
4333: 'Necklace', 298787: 'Pasta Maker'}
print(3 in inventory)
a) False
b) True
c) KeyError
d) "iron spear"
21
4. LEARN PYTHON: FILES
4.1 Reading a File Instructions
with open('welcome.txt') as text_file:
text_data = text_file.read()
print(text_data)
bad_bands_doc.write('The Beatles')
# Weren't expecting THAT were you??
22
4.5 Appending to a File Instructions
with open('cool_dogs.txt', 'a') as cool_dogs_file:
cool_dogs_file.write('Air Buddy\n')
setup = close_this_file.readline()
punchline = close_this_file.readline()
print(setup)
23
4.9 Reading Different Types of CSV Files Instructions
import csv
import csv
24
4.11 Reading a JSON File Instructions
import json
import json
__________________________________________
4. Quiz
1. What function would you use to render Python data to a JSON file?
a) json.dump()
b) json.writelines()
25
c) json.write()
4. Which of the following methods on a file object (called file_object) reads the
contents of a file and returns it as a string?
a) file_contents = file_object.readlines()
b) file_contents = file_object.readline()
c) file_contents = file_object.read()
d) file_contents = file_object.get()
5. What different modes, passed as arguments to the open() function, are there
for opening a file in Python?
a) Read-mode (‘r’, the default mode), Delete-mode (‘d’), and Update-mode
(‘u’).
b) Read-mode (‘r’, the default mode), Write-mode (‘w’), and Append-mode
(‘a’).
26
c) Read-mode (‘r’, the default mode), Write-mode (‘w’), and Update-mode
(‘u’).
6. What Python data type would you use to read in a CSV file as a dictionary?
a) csv.DictReader
b) json.load
c) csv.DictWriter
7. What method reads a single line from a file object variable called file_object?
a) file_object.read()
b) file_object.readline()
c) file_object.readlines()
__________________________________________
Project-2
import csv
import json
# Step 1
compromised_users = []
# Step 2
27
with open('passwords.csv') as password_file:
password_csv = csv.DictReader(password_file)
# Step 5
for password_row in password_csv:
# Step 6
compromised_users.append(password_row['Username'])
# Step 7
# print(password_row['Username'])
# Step 8
with open('compromised_users.txt', 'w') as compromised_user_file:
# Step 9
for compromised_user in compromised_users:
# Step 1
compromised_user_file.write(compromised_user + "\n")
# Step 3
boss_message_dict = {
"recipient": "The Boss",
"message": "Mission Success"
}
# Step 13
with open('boss_message.json', 'w') as boss_message:
28
# Step 15
json.dump(boss_message_dict, boss_message)
# Step 17
slash_null_sig = '''
_ _ ___ __ ____
/ )( \ / __) / \(_ _)
) \/ ( ( (_ \( O ) )(
\____/ \___/ \__/ (__)
_ _ __ ___ __ _ ____ ____
/ )( \ / _\ / __)( / )( __)( \
) __ (/ \( (__ ) ( ) _) ) D (
\_)(_/\_/\_/ \___)(__\_)(____)(____/
____ __ __ ____ _ _
___ / ___)( ) / _\ / ___)/ )( \
(___) \___ \/ (_/\/ \\___ \) __ (
(____/\____/\_/\_/(____/\_)(_/
__ _ _ _ __ __
( ( \/ )( \( ) ( )
/ /) \/ (/ (_/\/ (_/\
\_)__)\____/\____/\____/
'''
# Step 16
29
with open('new_passwords.csv', 'w') as new_passwords_obj:
# Step 18
new_passwords_obj.write(slash_null_sig)
30
5. INTRODUCTION TO CLASSES
print(type(5))
my_dict = {}
print(type(my_dict))
my_list = []
print(type(my_list))
facade_1 = Facade()
31
class Facade:
pass
facade_1 = Facade()
facade_1_type = type(facade_1)
print(facade_1_type)
32
circle = Circle()
pizza_area = circle.area(3 / 2)
teaching_table_area = circle.area(36 / 2)
round_room_area = circle.area(1560 / 2)
teaching_table = Circle(36)
alternative_rocks = Store()
isabelles_ices = Store()
33
5.10 Attribute Functions Instructions
can_we_count_it = [{'s': False}, "sassafrass", 18, ["a", "c", "s", "d", "s"]]
class Circle:
pi = 3.5
def __init__(self, diameter):
print("Creating circle with diameter {d}".format(d=diameter))
# Add assignment for self.radius here:
self.radius = diameter / 2
def circumference(self):
return 2 * self.pi * self.radius
medium_pizza = Circle(3)
34
teaching_table = Circle(36)
round_room = Circle(1560)
print(medium_pizza.circumference())
print(teaching_table.circumference())
print(round_room.circumference())
print(dir(5))
def this_function_is_an_object(num):
return "Cheese is {} times better than everything else".format(num)
print(dir(this_function_is_an_object))
class Circle:
pi = 3.5
35
def area(self):
return self.pi * self.radius ** 2
def circumference(self):
return self.pi * 2 * self.radius
def __repr__(self):
return "Circle with radius {radius}".format(radius=self.radius)
medium_pizza = Circle(3)
teaching_table = Circle(36)
round_room = Circle(1560)
print(medium_pizza)
print(teaching_table)
print(round_room)
class Student:
def __init__(self, name, year):
self.name = name
self.year = year
36
self.grades = []
class Grade:
minimum_passing = 65
__________________________________________
5. Quiz
37
def __repr__(self):
return "Hiya {}!".format(self.name)
devorah = User("Devorah")
print(devorah)
a) Hiya devorah!
b) devorah
c) Devorah
d) Hiya Devorah!
3. What does the hasattr() function call in the last line here evaluate to?
class HoldsFive:
five = 5
five_holder = HoldsFive()
hasattr(five_holder, 'five')
a) True
b) False
c) 5
__________________________________________
Project-3
Basta Fazoolin'
39
class Menu:
def __init__(self, name, items, start_time, end_time):
self.name = name
self.items = items
self.start_time = start_time
self.end_time = end_time
def __repr__(self):
return '{} menu available from {} to {}'.format(self.name, self.start_time,
self.end_time)
brunch_items = {
'pancakes': 7.50,
'waffles': 9.00,
'burger': 11.00,
'home fries': 4.50,
'coffee': 1.50,
'espresso': 3.00,
40
'tea': 1.00,
'mimosa': 1.50,
'orange juice': 3.50
}
brunch = Menu('brunch', brunch_items, '11am', '4pm')
early_bird_items = {
'salumeria plate': 8.00,
'salad and breadsticks (serves 2, no refills)': 5.00,
'pizza with quattro formaggi': 9.00,
'duck ragu': 17.50,
'mushroom ravioli (vegan)': 13.50,
'coffee': 1.50,
'espresso': 3.00,
}
early_bird = Menu('early_bird', early_bird_items, '3pm', '6pm')
dinner_items = {
'crostini with eggplant caponata': 13.00,
'caesar salad': 16.00,
'pizza with quattro formaggi': 11.00,
'duck ragu': 19.50,
'mushroom ravioli (vegan)': 13.50,
'coffee': 2.00,
41
'espresso': 3.00,
}
dinner = Menu('dinner', dinner_items, '5pm', '11pm')
kids_items = {
'chicken nuggets': 6.50,
'fusilli with wild mushrooms': 3.00,
'apple juice': 3.00
}
kids = Menu('kids', kids_items, '11am', '9pm')
print(brunch)
print(brunch.calculate_bill(['pancakes', 'home fries', 'coffee']))
print(early_bird)
print(early_bird.calculate_bill(['salumeria plate', 'mushroom ravioli (vegan)']))
class Franchise:
def __init__(self, address, menus):
self.address = address
self.menus = menus
def __repr__(self):
return 'Address: {}'.format(self.address)
42
def available_menus(self, time):
available_menus = []
for menu in self.menus:
if time >= menu.start_time and time <= menu.end_time:
available_menus.append(menu)
return available_menus
arepas_menu = {
'arepa pabellon': 7.00,
'pernil arepa': 8.50,
'guayanes arepa': 8.00,
'jamon arepa': 7.50
}
arepas_place = Franchise("189 Fitzgerald Avenue", [Menu("Take a' Arepa",
arepas_menu, '1am', '8pm')])
# create flagship_store and new_installment franchises
flagship_store = Franchise("332 West End Road", [brunch, early_bird, dinner,
kids])
new_installment = Franchise("3 East Mulberry Street", [brunch, early_bird,
dinner, kids])
43
# test out the available_menus method
print(flagship_store.available_menus("3pm"))
print(flagship_store.available_menus("5pm"))
class Business:
def __init__(self, name, franchises):
self.name = name
self.franchises = franchises
44
JAVA
1. HELLO WORLD
1.2 Program of Hello Java File! Instructions
public class HelloYou {
public static void main(String[] args) {
System.out.println("Hello Vishva!");
}
}
45
public static void main(String[] args) {
System.out.println("Hello Java!");
46
System.out.println("Programming is... fun!");
}
}
1.6 Program of Compilation: Catching Errors Instructions
public class Compiling {
public static void main(String[] args) {
}
}
1.8 Program of Java Review: Putting It All Together Instructions
public class Review {
public static void main(String[] args) {
// The main method executes the tasks of the class
System.out.println("My first Java program from scratch!");
}
}
__________________________________________
47
1. Quiz
1. What is missing from this Java program?
public class LanguageFacts {
______
James Gosling is a Canadian engineer who created Java while
working at Sun Microsystems. His favorite number is the
square root of 2!
______
49
}
}
• //
• \*\
• */*
• /*
• \\
• */
Click or drag and drop to fill in the blank
ANS:
public class Timeline {
public static void main(String[] args) {
/*
James Gosling is a Canadian engineer who created Java while
working at Sun Microsystems. His favorite number is the
square root of 2!
*/
}
}
__________________________________________
Project-1
Planting a Tree
// Define your tree class in this file!
50
public class Tree
{
public static void main(String args[])
{
//tree
System.out.println("I will be printed to the screen");
System.out.println(" * ");
System.out.println(" *** ");
System.out.println(" *** ");
System.out.println(" * ");
System.out.println(" * ");
}
}
OUTPUT
I will be printed to the screen
*
***
***
*
*
51
2. VARIABLES
2.1 Program of Introduction Instructions
public class Creator {
public static void main(String[] args) {
String name = "James Gosling";
int yearCreated = 1995;
System.out.println(name);
System.out.println(yearCreated);
}
}
2.2 Program of ints Instructions
//This is the class declaration:
public class CountComment {
//This is the main method that runs when you compile:
public static void main(String[] args) {
//This is where you will define your variable:
int numComments = 6;
//This is where you will print your variable:
System.out.println(numComments);
}
52
//This is the end of the class:
}
53
}
}
2.6 Program of String Instructions
public class Song {
public static void main(String[] args) {
String openingLyrics = "Yesterday, all my troubles seemed so far
away";
System.out.println(openingLyrics);
}
}
2.7 Program of Static Checking Instructions
public class Mess {
public static void main(String[] args) {
int year = 2001;
String title = "Shrek";
char genre = 'C';
double runtime = 1.58;
boolean isPG = true;
}
}
2.8 Program of Naming Instructions
public class BadNames {
public static void main(String[] args) {
54
String firstName = "Samira";
String lastName = "Smith";
String email = "[email protected]";
int salaryExpectation = 100000;
int yearOfBirth = 1955;
__________________________________________
2. Quiz
1. What line of code declares a variable called numRabbits to store a whole
number?
a) numRabbits int;
b) number numRabbits;
55
c) int numRabbits;
d) numRabbits = int;
2. Which one of the following values is a valid char?
a) “a”
b) ‘ab’
c) 7
d) ‘F’
3. Which option is a valid variable name and follows the Java naming
conventions?
a) TimeUntilLaunch
b) 2ndPhoneNumber
c) second_phone_number
d) timeUntilLaunch
4. What value CANNOT be assigned to a variable with the datatype double.
a) 6.7
b) 5
c) -.2
d) “60”
5. Which of the following lines would throw a compilation error?
a) int balance = -30;
b) double isRaining = false;
c) String gradeOnTest = "A";
d) char grade_on_test = 'F';
6. Which line declares the variable bestProgrammingLanguage and initializes it to
be "Java"?
a) String bestProgrammingLanguage = "Java";
b) bestProgrammingLanguage = String "Java";
c) string bestProgrammingLanguage = "Java";
d) "Java" = String bestProgrammingLanguage;
7. What datatype can only be assigned one of two values?
56
a) double
b) int
c) boolean
d) char
8. What is the value of num?
int num = (10 - (4 + 3)) * 6;
a) 24
b) 18
c) -32
d) 20
__________________________________________
Project-2
Java Variables: Mad Libs
public class MadLibs {
/*
*/
System.out.println(story);
58
}
OUTPUT
This morning Vishva woke up feeling excited. 'It is going to be a fantastic day!'
Outside, a bunch of activists were protesting to keep art in stores. They began to
chant to the rhythm of the drums, which made all the spectators very perplexed.
Concerned, Vishva texted John, who flew Vishva to Paris and dropped Vishva in a
puddle of frozen slush. Vishva woke up in the year 2050, in a world where robots
ruled the world.
59
3.Manipulating Variables
3.1 Program of Introduction Instructions
public class GuessingGame {
public static void main(String[] args) {
int mystery1 = 8+6;
int mystery2 = 8-6;
System.out.println(mystery2);
}
}
3.2 Program of Addition and Subtraction Instructions
public class PlusAndMinus {
public static void main(String[] args) {
int zebrasInZoo = 8;
int giraffesInZoo = 4;
60
3.3 Program of Multiplication and Division Instructions
public class MultAndDivide {
public static void main(String[] args) {
double subtotal = 30;
double tax = 0.0875;
System.out.println(total);
System.out.println(perPerson);
}
}
3.4 Program of Modulo Instructions
public class Modulo {
public static void main(String[] args) {
int students = 26;
System.out.println(leftOut);
}
61
}
3.5 Program of Compound Assignment Operators Instructions
public class BakeSale {
public static void main(String[] args) {
int numCookies = 17;
numCookies -= 3;
numCookies /= 2;
int expression3 = 5 * 4 % 3 - 2 + 1;
System.out.println(expression3);
62
}
}
3.7 Program of Greater Than and Less Than Instructions
public class GreaterLessThan {
public static void main(String[] args) {
double creditsEarned = 176.5;
double creditsOfSeminar = 8;
double creditsToGraduate = 180;
63
boolean sameNumberOfSongs = songsA == songsB;
boolean differentLength = albumLengthA != albumLengthB;
}
}
3.9 Program of Greater/Less Than or Equal To Instructions
public class GreaterThanEqualTo {
public static void main(String[] args){
double recommendedWaterIntake = 8;
double daysInChallenge = 30;
double yourWaterIntake = 235.5;
System.out.println(isChallengeComplete);
}
}
3.10 Program of .equals() Instructions
public class Song {
public static void main(String[] args){
String line1 = "Nah nah nah nah nah nah nah nah nah yeah";
64
String line2 = "Nah nah nah nah nah nah, nah nah nah, hey Jude";
String line3 = "Nah nah nah nah nah nah, nah nah nah, hey Jude";
System.out.println(line1.equals(line2));
System.out.println(line2.equals(line3));
}
}
3.11 Program of String Concatenation Instructions
public class Zoo {
public static void main(String[] args){
int animals = 12;
String species = "zebra";
String zooDescription = "Our zoo has " + animals + " " + species + "s!";
System.out.println(zooDescription);
}
}
3.12 Program of final Keyword Instructions
public class Final {
public static void main(String[] args) {
final double pi = 3.14;
System.out.println(pi);
}
65
}
3.13 Program of Review Instructions
public class BankAccount {
public static void main(String[] args){
double balance = 1000.75;
double amountToWithdraw = 250;
__________________________________________
3. Quiz
1. To what value does the following string concatenation evaluate?
"It's " + 5 + "pm"
a) "It's pm"
b) "It's 5pm"
c) Error
d) 11
2. True or False: The value of a variable declared with the final keyword can be
changed after its initial declaration.
66
a) True
b) False
3. How could we get a result of 10, given the following variable?
double a = 2;
a) a - 12
b) a % 10
c) a*5
d) a/2
4. What is the best way to tell if the following two Strings are equal?
String username1 = "teracoder";
String username2 = "gigacoder";
a) username1==username2
b) System.out.println(username1)
c) username1.isEqualTo(username2)
d) username1.equals(username2)
5. Which operator can be used to concatenate two Strings?
a) .equals()
b) -
c) +
d) *
6. The expression 5 != 6 will evaluate to what value?
a) true
b) 6
c) false
d) 5
7. After the following code is run, what value will the variable endpoint be
assigned to?
int endpoint = 11 % 3;
a) 2
67
b) 1
c) 11
d) 2.66
8. What will the following program output?
int num = 12;
num *= 2;
num -= 4;
num++;
System.out.println(num);
a) 20
b) 21
c) 9
d) 12
9. What does the following code do?
System.out.println(8 <= 8);
a) Prints true.
b) Prints 8.
c) Prints false.
d) Prints 0.
10. Are there any errors in this Java statement?
int status = 7 < 8;
a) There are no errors.
b) Yes, int should be boolean.
c) Yes, there should be no semicolon.
d) Yes, int should be char.
__________________________________________
Project-3
68
Math Magic
public class Magic {
69
// Print out the value of the last step
System.out.println(stepSix); // The output should be 3
}
}
OUTPUT
3
70