Imperative Programming Flashcards

1
Q

How do you break down System.out.println(“Hello”);

A

System.out.println = function
“Hello” = the argument, value passed into function
; = terminates the statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the parts of a variable initialisation?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between println() and print()?

A

println() prints a special newline character which starts a new line on the screen and print() doesn’t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you use printf()?

A

%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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you input in java?

A

import java.util.Scanner;
Scanner input = new Scanner(System.in);
input.nextInt() {waits for an integer}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you run a file in jshell?

A

jshell – execution local (file name).jsh

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to do you use switch cases?

A

switch(value) {
case ans1:
thing
break;
case ans2:
thing2
break;
default:
if the cases above are
not chosen
break;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you make conditional operator?

A

eg: System.out.println(studentGrade >= 60 ? “Passed” : “Failed”)
if it is true the first thing is printed if not the second is

How well did you know this?
1
Not at all
2
3
4
5
Perfectly