JAVA Week 1 Flashcards
How to write single and double line comments
// and /* ….. */
What is the command for reading input
import java.util.Scanner;
How is the input tool created
Scanner scanner = new Scanner(System.in)
When is the double, int, boolean variables used.
When double is a floating-point number, int is a whole number and boolean is a true or false value
Instead of spaces, what is used
camelCase
What is Integer.valueOf
Command that converts a string to an integer
Does a conditional statement mark the start of a new code block?
Yes
Why can you not compare strings with ==
Strings can hold a limitless amount of characters, whereas integers, floating-point numbers, and boolean values always contain a single number or value only.
What is .equals command
The equals command is written after a string by attaching it to the string to be compared with a dot.
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!”
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!"); } }
}