COW Computation Of the Week(3) Code 1 – Create a program that

advertisement
COW
Computation Of the Week(3)
Code 1 – Create a program that produces the following output to the screen. Each item sent to
standard output should be a value stored in a variable. That value should be modified in a loop:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
2, 4, 6, 8, 10, 12, 14, 16, 18, 20,
1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
1, 3, 7, 15, 31, 63, 127, 255, 511,
1, 4, 10, 22, 46, 94, 190, 382, 766,
1, 2, 5, 14, 41, 122, 365, 1094,
1, -10, 100, -1000, 10000, -100000,
1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
2, 4, 16, 256, 65536,
Task 2 – Think of 10 real life examples of arrays:
Code 3 – Complete the methods in the ArrayPractice Class. For each method, you may assume that
the array has exactly ten elements. The methods include:
printOut(int [] array) – print out all the elements of the array without using loops.
printOutInLoop(int [] array) – print out all the elements of the array using a loop.
printOutInReverse(int [] array) – print out all the elements of the array in reverse
without using loops.
printOutInReverseInLoop(int [] array) – print out all the elements of the array in
reverse using a loop.
doubleArray(int [] array) – doubles all the elements inside of the array.
sumArray(int [] array) – calculates the sum of all the elements in the array.
printPositives(int [] array) – print out all the positive numbers in the array.
printNegatives(int [] array) – print out all the negative numbers in the array.
printEvens(int [] array) – print out all the even numbers in the array.
printOdds(int [] array) – print out all the even numbers in the array.
printPositiveEvens(int [] array) – print out all the positive odd numbers in the array.
printNegativeOdds(int [] array) – print out all the negative even numbers in the array.
Code 4 – Complete the methods in the StringPractice Class. For each method, you may assume that
the array has exactly ten elements. The methods include:
printOutEachChar(String word) – print out all the letters in the string on separate lines. So
the String “Cat” would print out:
Char 1: C
Char 2: a
Char 3: t
printOutInReverse(String word) – print out the string in reverse.
Task 5 – Go to Coding Bat and see how many stars you can get in String 1
Code 6 – Write a program that takes in the first name and last name of two individuals. Have the
program say who has the longer first name, longer last name, and who has the longer name overall.
Then have the program tell the user whether either the first name or last name or both are the same.
Then have the program ask for a nickname for both and output to the screen. So, if Yaro was stored
for a first name, Mayewsky was stored in a last name, and Meany was stored as a nickname, the
computer output should read:
Yaro “the Meany” Mayewsky
Code 7 – Write a program that will ask the user a series of questions and based on how they answer, determine
which AP Computer Science student they are. The computer cannot ask the user for any part of their name.
The computer can at most ask the user 6 questions.
Task 8 – What variables would be needed for a playing card? How many would be needed for an entire deck?
Download