COSC 117 Flashcards

1
Q

What is a do-while loop

A

it is a loop that always executes at least onces

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

How to loop through a string?

A

String original=keyboard.nextLine();
String revisted=’’’;
for(int i=0;i<orginal.length(); i++)
char c=original.charAt(i);

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

How to write a switch statement using months, that would be read in by the user? The first and second month are the same.

A
int month=keyboard.nextInt();
switch(month){
case 1: case 2:
break;
case 3:
break;
default:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of methods?

A

reuse
separation of concerns
test it on its own

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

How to write a method?

A

public static int sum(int x, int y){
int result=x+y;
return result;
}

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

How to create a random number?

A
Random rand=new Random();
int num=rand.nextInt(x);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
What is the range of numbers?
Random random=new Random();
int num=random.nextInt(10);
A

0-9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
What is the range of numbers?
Random random=new Random();
int num=random.nextInt(9)+1;
A

1-9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
What is the range of numbers?
Random random=new Random();
int num=random.nextInt(5)+random.nextInt(3)+7;
A

7-13

because 4+2+7=13 and then the +7 means it starts at 7

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

How to read in information from the user?

A
Scanner keyboard=new Scanner(system.in);
int num=keyboard.nextInt();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is primary(ram) memory?

A

is temporary lost when turned off

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

What is secondary memory?

A

permanent, even without power.

Examples: hard disk, USB, CD

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

What is an expression?

A

always evaluates to a value

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

Is keyboard.nextDouble() an expression?

A

yes

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

is 23.09 an expression?

A

yes

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

is “HELLO WORLD” an expression?

A

yes

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

What type of code is LOD Y
SUB X
STO T1

A

assembler code

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

What is operator precedence?

A

the order which operations are done.
Example: 3+42
4
2 is done first

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

What is the order of precedence for( !, ||, &&)

A

!
&&
||

20
Q

What are three different control structures?

A

sequence
branching (if statement)
iteration (loops)

21
Q

When is a for loop used? How do you write it?

A

used when you know how many times to run the loop

for(int i; i<; i++);

22
Q
Convert while loop to a for loop
while(count<numOfexams){
syso
count++;
}
A

for(int count=0; count<numOfexams; count++)

23
Q

What is 2%3?

A

2

24
Q

what is 6%6?

A

0

25
Q

what is 4%3?

A

1

26
Q

what is 4%5?

A

4

27
Q

What data types can be used to represent real numbers? not integer

A

double

float

28
Q

What is the purpose of an import statement? What is an example?

A

The purpose is to use other classes in java. For example when using the Scanner class you have to import the code from the scanner class.

29
Q

What is the purpose of a sentinel value?

A

The purpose of a sentinel value is to help determine when a while loop will end. For example
while(num!=-1)
the sentinel value is -1

30
Q

To declare a variable, two pieces of information need to be specified what are they?

A
data type (string, int, double...)
name of the variable (int x;)
31
Q

System.out.printf(“Output:%.2f”, 3.14158676686);

A

output: 3.14

32
Q

false || ! (false && !false)

A

true

33
Q

false || !( true && !false)

A

false

34
Q

true || !(false && !true)

A

true

35
Q

true || !(true && !true)

A

true

36
Q

What is the output?
int x=3;
int y=4;
Syso(x+y+ “equals”+ y+x);

A

7 equals 43

37
Q

Wrtie 4/3pieR^3

A

(4.0/3) Math.PI Math.pow(r,3);

38
Q

What is the output?

syso(“dogs "+ (2+1)+ “+ “+ “are\n smart”);

A

dogs”+(2+1)+are

smart

39
Q

name 8 data types

A
int
Boolean
float
short
long
byte
char
40
Q

how to check if two strings are equal?

A

use .equals();

41
Q

What is a variable’s scope?

A

it is where in the code a variable can be used.

For example when writing multiple methods the variable within each method can only be used in that method.

42
Q

How to declare an array?

A

int array[]=new int[x];

43
Q

How to initialize arrays?

A

int [] scores= {5,3,2,3,4,5,};

44
Q

In an applet, when drawing a line what are the numbers that are read in?

A

(int x1, int y1, int x2, int y2)

45
Q

In an applet, when drawing a shape what are the numbers that are read in?

A

(int x, int y, int width, int height)