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( !, ||, &&)

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?

24
Q

what is 6%6?

25
what is 4%3?
1
26
what is 4%5?
4
27
What data types can be used to represent real numbers? not integer
double | float
28
What is the purpose of an import statement? What is an example?
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
What is the purpose of a sentinel value?
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
To declare a variable, two pieces of information need to be specified what are they?
``` data type (string, int, double...) name of the variable (int x;) ```
31
System.out.printf("Output:%.2f", 3.14158676686);
output: 3.14
32
false || ! (false && !false)
true
33
false || !( true && !false)
false
34
true || !(false && !true)
true
35
true || !(true && !true)
true
36
What is the output? int x=3; int y=4; Syso(x+y+ "equals"+ y+x);
7 equals 43
37
Wrtie 4/3pieR^3
(4.0/3) *Math.PI* Math.pow(r,3);
38
What is the output? | syso("dogs \"+ (2+1)+ "+ "+ "are\n smart");
dogs"+(2+1)+are | smart
39
name 8 data types
``` int Boolean float short long byte char ```
40
how to check if two strings are equal?
use .equals();
41
What is a variable's scope?
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
How to declare an array?
int array[]=new int[x];
43
How to initialize arrays?
int [] scores= {5,3,2,3,4,5,};
44
In an applet, when drawing a line what are the numbers that are read in?
(int x1, int y1, int x2, int y2)
45
In an applet, when drawing a shape what are the numbers that are read in?
(int x, int y, int width, int height)