COSC 117 Flashcards
What is a do-while loop
it is a loop that always executes at least onces
How to loop through a string?
String original=keyboard.nextLine();
String revisted=’’’;
for(int i=0;i<orginal.length(); i++)
char c=original.charAt(i);
How to write a switch statement using months, that would be read in by the user? The first and second month are the same.
int month=keyboard.nextInt(); switch(month){ case 1: case 2: break; case 3: break; default:
What is the purpose of methods?
reuse
separation of concerns
test it on its own
How to write a method?
public static int sum(int x, int y){
int result=x+y;
return result;
}
How to create a random number?
Random rand=new Random(); int num=rand.nextInt(x);
What is the range of numbers? Random random=new Random(); int num=random.nextInt(10);
0-9
What is the range of numbers? Random random=new Random(); int num=random.nextInt(9)+1;
1-9
What is the range of numbers? Random random=new Random(); int num=random.nextInt(5)+random.nextInt(3)+7;
7-13
because 4+2+7=13 and then the +7 means it starts at 7
How to read in information from the user?
Scanner keyboard=new Scanner(system.in); int num=keyboard.nextInt();
What is primary(ram) memory?
is temporary lost when turned off
What is secondary memory?
permanent, even without power.
Examples: hard disk, USB, CD
What is an expression?
always evaluates to a value
Is keyboard.nextDouble() an expression?
yes
is 23.09 an expression?
yes
is “HELLO WORLD” an expression?
yes
What type of code is LOD Y
SUB X
STO T1
assembler code
What is operator precedence?
the order which operations are done.
Example: 3+42
42 is done first