Chapter 2 - Input/Output and Operators Flashcards

1
Q

// does what in a program ?

A

end-of-the-line comment

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

/*

A

traditional comment

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

declare a class

A

public class Class{}

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

what two things must be the same in java in order for the application to run?

A

the class name and the file name

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

sample code that prints out “Hello World”

A

System.out.print(“Hello World”);

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

system.out.printIn

A

prints output followed by new line

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

system.out.print

A

prints output without a new line

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

system.out.printf

A

displays formatted data

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

%s

A

string

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

%d

A

is a format placeholder for int (integer)

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

%f

A

double and float

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

%b

A

boolean

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

%n

A

newline

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

%t

A

tab

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

%20 does what?

A

creates a 20-character position, right justified

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

what code does a java program need in order to read user input?

A

import java.util.Scanner

17
Q

what code creates a scanner object in java?

A

Scanner input = new Scanner (System.in)

18
Q

what code reads user input as a double value?

A

double number1 = input.nextDouble();

19
Q

what code reads as an integer?

A

int number1 =input.nexInt();

20
Q

what code reads user input as a string ?

A

String myvalue = input.nextLine();

21
Q

float vlaue

A

flloat number1=input.nextFloat();

22
Q

Boolean

A

boolean myvalue = input.nextBoolean();

23
Q

compile a program

A

javac Program1.java

24
Q

execute a program

A

java Program1

25
Q

code for instant variable

A

private String name;

26
Q

instance variable

A

because it is private only certain classes can access it

27
Q

local variable

A

public void setName(String name){this.name = name;}

28
Q

local variable definition

A

a variable that is declared within a method and cannot be accessed by statements that are outside the method

29
Q

primitive types

A

int,float,double,boolean,short,byte,long,char

30
Q

nonprimitive

A

reference types

31
Q

set method code

A

public void setName(String name){ this.name=name;}

32
Q

get method code

A

public String getName(){ return name;}

33
Q

what is a constructor

A

implicitly by the new operator

34
Q

two things that must be the same in a constructor to avoid syntax errors

A

class name and constructor name

35
Q

sequential execution

A

one after the other