Level 1 - Intro to Java Flashcards

1
Q

What is the escape sequence for creating a new line?

A

What is the escape sequence for creating a new line?

\n

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

What symbol terminates every line?

A

What symbol terminates every line?

;

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

Write two lines of code where the first prints “Hello”, the second prints “world”, and the net result is that they print together exactly as follows:
Helloworld

A

Write two lines of code where the first prints “Hello”, the second prints “world”, and the net result is that they print together exactly as follows:
Helloworld

System.out.print(“Hello”);
System.out.println(“world”);

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

In the following two lines of code, state which line is initializing and which is declaring.
int siv;
siv = 14;

A

int siv; //declaring

siv = 14; //initializing

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

What is output by the following code?
int x = 22;
int y = 6;
System.out.println(x % y);

A

4

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

What are the data types that we are able to input from the keyboard?

A

String, Int, double

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

Which of the following is illegal?

a. double d = 27;
b. int i = 203.932;

A
b.
int i = 203.932;
//int types can't hold decimals
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the three different types of primitive variables that we have learned so far?

A

String, int, and double

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

Declare a string called myString that initializes to: Computer Science

A
String myString = "Computer Science";
//don't forget the quotes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What will the following code print out?

String s = “Mona Lisa”;
System.out.println(s.length( ));

A

String s = “Mona Lisa”;
System.out.println(s.length( ));

//Outputs
9
//remember to count the space between words
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the escape sequence for a tab?

A

What is the escape sequence for a tab?

\t

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

What does this mean: 1.45667E24

A

What does this mean: 1.45667E24

1.45667 x 10^24

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

What would the following print out:

System.out.println( “my dog has fleas”.substring(4) );

A

What would the following print out:
System.out.println( “my dog has fleas”.substring(4) );

og has fleas

//start at character with index 4 until the end

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

What would the following print out:

System.out.println( “my dog has fleas”.substring(5, 9) );

A

g ha

//started at index 4 and end just before index 9

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

What is another way to write:

x = x + 1;

A

x++ or ++x

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

What is this compound operator short for:

x+=y-4;

A

x = x + (y-4);

17
Q

1%3 = ?

A

0

18
Q

What is the scanner method to look for a String input

A

nextLine()

19
Q

How does one represent pi using the math class

A

Math.PI

//PI is all caps and not () follow it

20
Q

Which of these lines will result in an error:
A). double x = 14.7;
Int y = x;

B). int x = 14;
double y = x;

A

A

//there is a potential loss of precision.

21
Q

How does one add a comment for personal use?

A

//