Java Puzzles to Eliminate Code Fear

A method is a set of code

 

variable
string
return
void
method
String
-equals
-equalsIgnoreCase
-Indexof
-LastIndexOf
-!equals
-String.substring
char
TestingUtils.runTests()
Conditionals

 

Scenario:
We have a loud barking dog. The “hour” parameter is the current hour time in the range 0 to 23. We are in trouble if the hour is before 7 or after 20. Return true if we are in trouble

While Loop:

code:

output:

For Loop:

Reverse character:

Print  even number from 0 to 100:

Sending parameters as an array

Cool recursion example instead of loop:

SpeedingFine Assignment:

my logic:

 

We always try to make the code short and sweet: Logic from the course instructor

Short and sweet code:

 

Another logical problem:

Singing code by me:

Also by ternary operator in one line:

In one line with ternary operator

Ass_06:

Amar VuulVaal code:

 

Valo code FizzyWizzy :P::

Assignment_09 my own solution:

Logic from the instructor:

 

 

 

 

Spread the love