5. FizzBuzz 2.0
by CodeChum Admin
Remember the game of FizzBuzz from the last time? Well, I thought of some changes in the game, and also with the help of loops as well. Firstly, you'll be asking for a random integer and then loop from 1 until that integer. Then, implement these conditions in the game:
print "Fizz" if the number is divisible by 3
print "Buzz" if the number is divisible by 5
print "FizzBuzz" if the number is divisible by both 3 and 5
print the number itself if none of the above conditions are met
Input
A line containing an integer.
15
Output
Multiple lines containing a string or an integer.
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
4. Jackpot!
by CodeChum Admin
Did you know that in lotteries, a 3-digit number with the same numbers in all digits like 777 will hit the jackpot in a casino? In the same manner, let's make a program that will test if a certain 3-digit number hits a jackpot or not by identifying if all the digits of a given number is the same as the second inputted number. If it is, print "Jackpot!"; else, print "Nah".
Let's try this out now!
Input
A line containing two integers separated by a space.
777·7
Output
A line containing a string.
Jackpot!
3. The Positive Ones
by CodeChum Admin
There are different kinds of numbers, but among them all, the most commonly used numbers in our daily lives are those positive ones. So, I only want you to count all the positive numbers from the 4 outputted values and print out the result.
Go and search for the positive ones among these four!
Input
A line containing four numbers (may contain decimal places) separated by a space.
2·-4·3.6·1
Output
A line containing an integer.
3
2. Where's the Biggest One?
by CodeChum Admin
We've already tried comparing 3 numbers to see the largest among all, so let's try a more complicated mission where we locate the position of the largest among 5 numbers. There are only 4 possible cases for this mission:
- if the largest digit is the first digit, print "Leftmost"
- if the largest digit is the third digit, print "Middle"
- if the largest digit is the last digit, print "Rightmost"
- if none of the above is correct, print "Unknown"
Now, show me how far you've understood your lessons!
Input
A line containing a five-digit integer.
1·4·6·3·2
Output
A line containing a string.
Middle
Write a recursive method named series (int a, int n) that takes as a parameter an integer that may compute the following series:
-2, 7, 52, 2702… if a = -2 and n = 4
Then, write a full program to solve the above problem using recursion.
Procedure:
1. Create a folder named LastName_FirstName in your local drive. (ex. Reyes_Mark)
2. Using NetBeans, create a Java project named MovieTime. Set the project location to your own folder.
3. Import Scanner, Queue, and LinkedList from the java.util package.
4.Create two (2) Queue objects named movies and snacks.
Write a recursive method named series (int a, int n) that takes as a parameter an integer that may compute the following series:
-2,7,52,2702... if a=-2 and n=4
Then, write a full program to solve the above problem using recursion.
Which are the best logical steps to code an isSublist(..). method that receives a linked list as parameter called plist and determine if all the elements are present in the calling list straight after each other. Ex.
[1,2,3,4,5,6] [2,3,4] true [2,4,5] false.
Consider two linked lists list1 with Integer values [1,2,3] and list2 with Integer values [4,5,6,7,8,9]
Suppose the merge method is called on list1 with list2 as parameter.
How many time will the following loop while((ptrThis != null) && (ptrParam != null)) iterate? Blank 1. Fill in the blank, read surrounding text.
After 3 iterations what will the value of ptrThis be? Blank 2. Fill in the blank, read surrounding text.
What will the value of ptrParam be? Blank 3. Fill in the blank, read surrounding text.
Do the pointer in both lists reach null at the same time? Yes/No Blank 4. Fill in the blank, read surrounding text.
What follows is a fill in the blank question with 9 blanks.
The curly bracket used in java to enclose units of code can not be used in a fill in questions. For this
questions the curly brackets will be substituted with comments. Interpret the open and close comments as curly brackets.
Given the following method with an array values [7,2,5,8,3,9]
public static int sumValues(int index)
//open method
if(index>=values.length)
return 0;
else
return values[index] + sumValues(index +1);
//close method
Is sumValues(4) a valid call? Yes/No Blank 15. Fill in the blank, read surrounding text.
If so what is returned from the method? returned value or No Blank 16. Fill in the blank, read surrounding text.
Is sumValues(1) a valid call? Yes/No Blank 17. Fill in the blank, read surrounding text.
If so what is returned from the method? returned value or No Blank 18. Fill in the blank, read surrounding text.