1331
int x = 3; int y = 2; double w = x / y; What is the value held in w after the following lines of code is executed?
1.0
int s = 10; int t = 3; int u = 7; What is the System.out.println(s * t + u / s);
30
String myString = "33333"; myString.replace("3", "e"); System.out.println(myString); What is the output of the following code snippet?
33333
int x = 5; int y = 2 System.out.println(x + y * 5/3); What is the output of the following code?
8
int days = 9; int daysLeft = days--; System.outprintln(daysleft); System.put.println(days); What is the printed by the following code?
9 8
String fruit = "Banana"; System.out.println(fruit.toUpperCase()); System.out.println(fruit.substring(1,3)); What is the output of the following code snippet?
BANANA an
Scanner input = new Scanner(System.in); String dataOne = myScanner.next(); String dataTwo = myScanner.nextLine(); System.out.println(dataOne); System.out.println(dataTwo); User types in: Data one: Hi! Data two: I take CS1331!
Hi! I take CS1331
What is the math class?
It contains all static methods and constants we can use in our programs
Make a power math statement with 2^4
Math.pow(2,4)
int horsepower = 15; if (horsepower > 15) if(horsepower <= 20) System.out.println('There is a lot of horsepower"); else System.out.println("The car super fast"); What gets printer?
Nothing
What are the idea of encapsulaton?
Objects should be self governing, each object should take care of its own data
Assuming the interest has a value of 2. What is the output of the following code? if (interest > 2) System.out.println("Interest rates are greater than 2%); System.out.println("The interest rates are pretty low");
The interest rates are pretty low
True or false: Can constructors have any number of parameters?
True
Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as a _________, which stores elements in a last in first out fashion.
stack
Why are visibility modifiers necessary
they can be used to selectively hide portions of the class, fulfilling the fundamental OOP concept of encapsulation
True or false: do constructors have to have the same name as the name of the class
true
String fruit1 = "Pear"; String fruit2 = "Pear"; String fruit3 = new String("Pear"); System.out.println(fruit1 == fruit2); System.out.println(fruit2 == fruit3); System.out.println(fruit2.equals(fruit3)); What is the output of the following code snippet?
true, false, true
Suppose your method does not return any value, which of the following can be used as a return type
void
List all the primitive types
double, short, char, long boolean
public class Car { public String name; public Car (string name) { this.name = name; System.out.println("name: " + name); } } public class CarDriver { public static void main(String [] args) { Car c = new Car( ); System.out.println("Cool car!"); } } What is the output and why
error because
public class Example { private int[] data; public Example(int [] values) { data = values; } public static void main(String [] args) { Example ex1 = new Example(new int []{1,2,3}); Example ex2 = new Example(ex1.data); ex1.data[0] = 9; ex2.data[1] = 6; } }
ex1 == {9,6, 3} ex2 == {9,6,3}
True or False: You always have to use this 'this' keyword inside of constructor
false
True or false: it can have a return type and value
false
int myID = 1234; myID = true; True or false: is this code legal
false
int myId = 1234; float myId = 45.7;
false
true or false; is String a primitive stype
false
Make a for loop that will execute the body of the loop 10 times
for (int i = 0; i < 10; i++){}
for (int count = 0; count < 12; count++){ System.out.println("Loops and more loops!"); } change in to for- loop
int count = 0; while (count < 12) { System.out.println("Loops and more loops!); count++ }
What is the proper way to declare and initialize an integer(whole number) called "count" that has the value 17?
int count = 17;
Which of the following are invalid identifies? myVar 9*3 a++ my_id MyID #acb
invalid identifiers
the signature of a method consists of
method name and parameter list
public class Car { public String name; public Car (string name) { name = name; } } public class CarDriver { public static void main(String [] args) { Car c = new Car("Camaro"); System.out.println(c.name); } } What is the output and why
null,
name two visibility modifiers
private and public
randomly generate an integer between 1 and 10 inclusive. The random object is called rand has already been declared and initialized
rand.nextInt(10) + 1;
What type is string
reference type
int revenue = 300; if (revenue > 50 { if (revenue < 100) { System.out.println("Revenue is greater than 50"); System.out.println("If block!); } else if (revenue > 100 { System.out.println("Revenue is greater 100") System.out.println("Else Block!"); } What gets printed?
"If block!"
int counter = 2; while (counter < 10) { counter++; } System.out.print(counter); What gets printer?
10
int s = 10; int t = 3; int u = 7; What is the System.out.println (s * (t + u) / s);
10
int s = 10; int t = 3; int u = 7; What is the System.out.println((s * t + u) / s)
3
How do you declare a variable named cold and correctly assign the value of true to it?
boolean cold = true;
System.out.print("apple"); System.out.print("banna); System.out.print("grape); System.out.print("Strawberry); What is the output of the following code snippet?
applebananagrape strawberry