This is the print statement in Java (either one)
System.out.println() or System.out.print()
What is the variable type used for true/false values?
boolean
What is PEMDAS an abbreviation for?
parenthesis, exponents, multiplication, addition, and subtraction
How can you check if two int or double values are the same?
==
How can you check if two String variables are equal?
String1.equals(String2);
Have a rational number? Use this variable type that stores decimals!
double
This is the expression used to compare two values (non-Strings)
What is == (double equals)?
What is the property can be used to solve this problem?
(x+y+z)(a+b+c)
What is distributive property
How can you check if two String values are the same?
.equals()
What's the difference between scanner.nextLine() and scanner.nextInt();
scanner.nextLine() gets a String value whicle scanner.nextInt() gets an int value
What does this code segment do?
i=i+1
adds 1 to i
All java data types (that we've gone over):
primitive: int, double, boolean, char, and object: String
What is the equation for a linear function? (straight line on graph)
y = mx+b
How do you set up a while loop?
while (condition is true) {
do this;
}
How could you use an if statement to check if a int number is even or odd?
if (number<0) {
System.out.println(number + " is odd");
} else {
System.out.println(number + " is even");
How would you create a variable for the price of chips and set it to $2.50?
double chipPrice = 2.55;
or
double chipPrice;
chipPrice = 2.55;
What are the two lines of code that we put before all of our java programs?
public class name {
public static void main (String[] arg) {
}
}
What is 24,0310 ?
1
Hint: You typically do this by using a specific operation
What's wrong with this code? (assume all code before this segment is correct)
1. Scanner myScanner = new Scanner(System.in)
2. String userAnswer;
3. System.out.println("What is your answer?")
4. useranswer = myScanner.nextInt();
- Lines 1 and 3: No ; after the line
- Line 4: useranswer does not match the variable userAnswer
- Line 4: .nextInt() is wrong because userAnswer is a String
This function from the Java library takes in user input.
java.util.Scanner
the class name
Evaluate this expression:
(52+3)-(3-5)2
24
String weather;
weather = scanner.nextLine();
Set up a sequence of if statements to print "yay" if the weather is sunny, ":(" if the weather is rainy, and otherwise print "whatever"
if (weather.equals("sunny")) {
System.out.println("yay");
} else if (weather.equals("rainy") {
System.out.println(":(");
} else {
System.out.println("whatever");
}
What does this code do?
for (int i = 5; i < 0; i--) {
System.out.println(i);
}
Prints
5
4
3
2
1