Test 1 Flashcards
How do you output statements?
System.out.println(“”);
or
System.out.print(“”);
How do you state a variable as a whole number?
int x;
How do you state a variable as a whole number? plus assign a value?
int x = 3;
How do you state a variable as a decimal number?
double x;
How do you state a variable as a decimal number? plus assign a value?
double x = 3.05;
Import the scanner at the start
import java.util.Scanner;
Make a Scanner object
Scanner input = new Scanner(System.in);
Make a Scanner do its stuff (the object is called input) (string is called x)
x = input.next();
What is the Scanner Input.next””(); if Its a Integer or Double
nextInt
nextDouble
What is the difference between == & = ?
== Is a check for truth and false
= Assigning a value to a variable
What is % represent
modulo. its the remainder of a division. Wait…… I can make a long division thing!
8 % 3 =
2
9 % 2 =
1
15284286 % 2 =
0 Because its all even…. except the 5…. it still works out
x = 4;
y = x++;
z = 5 + x;
((y == 5) && (x == 5) && (z <= 10))
T || F
False, y is not equal to 5 but 4
z is 10
x is 5
y = x++;
y = ++x;
Difference?
yes, (y = x)++ is direct.
The ++ is not between the y = x so first assign the variable then add 1.
(y = ++x) is not direct. The ++ is in between the variables so add 1 then assign.
Java reads from
right to left
x += 2;
This is a short version of x = x +2
This is basically adding 2 to the value of x.
x/= y;
Anything wrong with this
code?
int x = 6
int y
x /= 2
x = y
x = 3
y = 3
Yeah BIG PROBLEM
No semicolons?
What is ‘=!’
nothing…. like it doesn’t do anything I think….
What is ‘!=’
Is not equal to
What is ‘!’
Not
Were do you put the operations + - / * % > <
x = x ‘insert operation’ 2
Behind the =
x -= 2
what does && represent
and
what does || represent
Or
format of a switch statement? string = k
one switch is hi. Add default
switch (k)
{
case “hi”:
System.out.println(“hi”);
break;
case “2”:
x = 2;
break;
default:
System.out.println(“erm what the sigma?”);
}
while poop
while (0 == 0){
System.out.println(“POOOP”);
System.out.println(“POOP”);
System.out.println(“POP”);
}