Test 2 Flashcards
We gota do some recap… If you know this then just 5 star it
yeah and 5 star this too
Import a scanner into the class.
import java.util.Scanner;
Make a scanner object.
Scanner input = new Scanner(System.in);
User input for a int variable
int x = input.nextInt();
Make a While loop with a condition it a int x is not int y
while (x != y){
//Code here
}
what is a condition?
Its kinda like a true or false statement.
It turns a set of instructions into a true or false.
What happens if a condition is true? What happens if it’s false?
In terms of a while loop “True = run”, “False = don’t run just skip”
What does it mean to break out of a loop?
It means the condition is false and it does not run the loop again.
What is a for loop?
What are the parameters for?
A specific loop that acts with parameters (not the ones from before, I think)
for (variable for counting; number of loops; Increments or decrements){
//Code here
}
What is a for loop used for?
Easy way to count how many times you ran a program/you can tell it how many times to run.
while loop, you gotta do more stuff to do that is annoying… tbh its prob easier to use while loops.
What is an if statement?
Sadly, the name gives it away
it’s a set of commands given and executed due to the value of the condition on the if, and else if. The else at the end is like a default in a switch statement.
Structure of an if statement.
if (Condition) {
//Code here
}
else if (Condition) {
//Code here
}
else {
//Code here
}
Try-Catch Block? So like why does it exist?
A Try Catch Block is a made so that you can catch things like errors before it breaks your program. The one we learnt is the one for errors.
Try-Catch for any error structure.
try
{
//Code you want to make sure doesn’t break
{
catch(Exception e)
{
//What happens when there is an error?
}
Ok ok ok methods
So like why? Why make methods?
Why make functions in math? Well, so that you can see all the values and not just one. Also, it gets very useful and it is used everywhere.
What is a public static void mainbalablabla???????!?!?!?!?
So like java is object-oriented and that’s why agam doesn’t wanna learn it.
C
Printf(“”);
Java
public static void main(string[] arg){
System.out.println(“”);
}
What is void?
It means that everything in the method, if called, will run.
What is a type that is returned?
So a return type is a Method that, when called, will give you whatever the type is.
For example:
public static int(){
int x = 4;
return x;
}
What are parameters?
Parameters are Information given when calling a method. This is like math kinda… When you give y as 3 it gives you x as 6.