Challenges

Remember the rules for this are

  • Try to use only the information given up to this point in this book.
  • Try not to give up until you've given it a solid attempt

Challenge 1.

Write code that outputs every number from 1 to an arbitrary number

You are not allowed to use while or for loops.

// CODE HERE

void main() {
    int n = 30;

    // CODE HERE
}

Challenge 2.

Write code that will output each character of name on its own line.

So if name is equal to "Riyo", I would expect the following as output.

R
i
y
o

You are not allowed to use while or for loops.

// CODE HERE

void main() {
    String name = "Rudo";
    
    // CODE HERE
}

Challenge 3.

Write code that will take a number and if it is divisible by two, divides it by two. If it is not, multiplies it by three and adds one.

Keep doing this until the number equals one. Output it each time.

If the initial number is 6 you should have this as output.

6
3
10
5
16
8
4
2
1

You are not allowed to use while or for loops.

// CODE HERE

void main() {
    // Change this value to test your code.
    int n = 15;

    // CODE HERE
}

Challenge 4.

Write code that outputs the number of vowels in name. Treat y as a vowel.

Treat the characters a, A, e, E, i, I, o, O, u, U, y, and Y as vowels.

You are not allowed to use while or for loops.

// CODE HERE

void main() {
    // Change this value to test your code.
    String name = "Zanka";

    // CODE HERE
}

Challenge 5.

Draw a square.

Make it so that you can make the square bigger or smaller by changing a variable at the start of the program.

*****
*****
*****
*****

You are not allowed to use while or for loops.

// CODE HERE

void main() {
    int size = 5;

    // CODE HERE
}