If all the code snippets below assume properly that an ...
Name____________________________________ APCS A (Java Concepts Worksheet)
Beneath each header below, type or write a brief code snippet.
Be sure to properly declare && || initialize appropriate local variables.
For example;
int x, y, temp, sum;
double average;
boolean isEven = false;
If the problem calls for an array, assume the following array instantiation;
int[] myArray = new int[10];
…
How to average correctly – the simple version!
Type code here.
// the key here is to cast the sum to a double.
How to average correctly in an array
Type code here. Don’t forget your “for” loop!
// the key here is to cast the sum to a double to not lose decimal data
How to find max/min in an array
Type code here. Don’t forget your “for” loop!
// the key here is to properly initialize max and min before entering the for loop
How to swap elements – the simple version!
Begin code here.
// the key here is to perform the swap in the correct order
How to swap elements in an array – the simple version!
Type code here. No loop this time – just a simple swap.
// the key here is to perform the swap in the correct order
How to reverse an array
Begin code here. Remember you’re only looping through half of the array!
// the key here is to perform the swap in the correct order through just half of the array
How to increase the size of an array
Begin code here.
Explain the differences between selection sort and insertion sort algorithms. When would you use one over the other?
Type answer here.
How to turn a number into a String
int x;
String y;
Type answer here…
How to prompt users for input. What lines are necessary to “scan” for input?
Type answer here…
How to compute/generate a random number.
// HINT: you will need to use the math class to do this.
int num1;
double num2;
// First, generate random integer from 0 to 9
Type answer here…
// Second, generate random integer from 1 to 10
Type answer here…
// Third, generate random integer from 20 to 34
Type answer here…
// Fourth, generate random decimal from 0 to 0.99
Type answer here…
// Fifth, generate random decimal from 0 to 5.99
Type answer here…
How to extract individual digits from an integer.
// HINT: the concept is called modulus and you will need to use % operator(remainder)
int num = 12345;
int digitNum; // will be the extracted number
// get the ones digit
Type answer here…
// get the tens digit
Type answer here…
// get the hundreds digit
Type answer here…
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- how to properly start an essay
- are the functions given below exponential functions
- all the prayers in the bible pdf
- how to properly acknowledge an email
- all the words in the english language
- all the words in the world list
- all the words in the world
- all the phases of the moon
- all the events that happened in 2020
- how to properly cite an article apa
- all the things that happened in 2020
- how to properly structure an essay