Imperative Programming Flashcards
How do you break down System.out.println(“Hello”);
System.out.println = function
“Hello” = the argument, value passed into function
; = terminates the statement
What are the parts of a variable initialisation?
eg: String x = “hello”;
String is the type of variable
x is the name of the variable
= indicates assignment
“hello” is the initial value
; terminates the statement
What is the difference between println() and print()?
println() prints a special newline character which starts a new line on the screen and print() doesn’t
How do you use printf()?
%s is a format specifier that substitutes the next argument (s is for string different letter for different types)
%n is a format specifier that substitutes an new line
put the arguments at the end separated using commas
eg: System.out.printf(“hello %s, you are %d years old%n”, name, age);
How do you input in java?
import java.util.Scanner;
Scanner input = new Scanner(System.in);
input.nextInt() {waits for an integer}
How do you run a file in jshell?
jshell – execution local (file name).jsh
How to do you use switch cases?
switch(value) {
case ans1:
thing
break;
case ans2:
thing2
break;
default:
if the cases above are
not chosen
break;
}
How do you make conditional operator?
eg: System.out.println(studentGrade >= 60 ? “Passed” : “Failed”)
if it is true the first thing is printed if not the second is