Young Coders: Week 2 Problems

Candy Challenge!

Finish at least 3 out of 5 of the following problems correctly to win candy/chocolate. Email your solutions to me, plus two or three of your favorite types of candy/chocolate.


1) Using a Scanner, read in 10 integers into an array. Print out “positive” if most of them are positive. Print out “negative” if most of them are negative. Print out “balanced” if five of them are positive and five of them are negative. (Assume none of the integers are zero.) 

2) Read in 5 integers into an array using a Scanner. Print out the numbers shifted left by one. 
For example,


{1,2,3,4,5} becomes {2,3,4,5,1} 


(EDIT: Please solve 3, 4, and 5 recursively!) 


3) Create a method called power that takes two parameters: base and exp. It returns the value of base to the exp power. For example:

power(2,3) = 8
power(5,3) = 125
power(4,0) = 1
4) Create a method called remove that takes one parameter: a String. It returns the same String, except all the ‘o’ or ‘O’ characters have been removed.
For example,

remove(“to be or not to be”) = “t be r nt t be”

5) Create a method called reflection. It has at least one parameter: an integer array. You decide if it should take any other parameters. The method should recursively check if the array contains two consecutive values such that one integer is the negative of the other. Return true or false (a boolean).
For example,

{1,4,-4,5,6,7,5} will return true because 4 and -4 are “reflections” of each other, and the two integers are right next to each other. 

Popular posts from this blog

Space Race: a simple Rust game built on the Bevy framework

Building a Toy Language Compiler in Go

tldr: Raft + Implementation Tips