JAVA Week 1 Flashcards

1
Q

How to write single and double line comments

A

// and /* ….. */

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

What is the command for reading input

A

import java.util.Scanner;

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

How is the input tool created

A

Scanner scanner = new Scanner(System.in)

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

When is the double, int, boolean variables used.

A

When double is a floating-point number, int is a whole number and boolean is a true or false value

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

Instead of spaces, what is used

A

camelCase

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

What is Integer.valueOf

A

Command that converts a string to an integer

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

Does a conditional statement mark the start of a new code block?

A

Yes

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

Why can you not compare strings with ==

A

Strings can hold a limitless amount of characters, whereas integers, floating-point numbers, and boolean values always contain a single number or value only.

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

What is .equals command

A

The equals command is written after a string by attaching it to the string to be compared with a dot.

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

Write a program that prompts the user for a password. If the password is “Caput Draconis” the program prints “Welcome!”. Otherwise, the program prints “Off with you!”

A

import java.util.Scanner;

public class MOOC1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Password");
        String input = String.valueOf(scanner.nextLine());
    if (input.equals("Caput Draconis")) {
        System.out.println("Welcome");
    }
    else {
        System.out.println("Off with you!");
    }
}

}

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