Java Tutorial [#05.5] - First coding challenges -> Solutions

in programming •  7 years ago  (edited)

Header.jpg

Disclaimer!
If you find any mistakes in this post or you don't know what to do at a specific point? Feel free to write me a comment! 👍
Greets from Germany ✌️

Last Part Next part
<- #05 First coding challenges #06 Methods and return statements ->

This is the another half of the fifth part. Here are the solutions for the challenges.

Half pyramid


You are only allowed to use 2 for-Loops. Now just think logically and you get following code:
for(int i = 0; i <= 10; i++){
for(int j = 0; j <= i; j++){
System.out.print("t ");
}
System.out.println();
}

Easy counter


In this task, you were only allowed to use 1 while-Loop and it counts as high as you want. This is very easy too:
int x = 0;
while(x <= 10){
System.out.println(x);
x++;
}

Sphere surface to radius


This is very tricky, especially for beginners. The code for this should look like this:
double o = 10;
if(o <= 0.0){
System.out.println("ERROR: o is too small");
}else{
System.out.println("Calculating the radius out of o");
System.out.println("-./(o / (4PI))\\");
System.out.print("-./( " + o + " / (4
PI))\\ = ");
System.out.println(Math.sqrt(o/(4*Math.PI)));
}

Last Part Next part
<- #05 First coding challenges #06 Methods and return statements ->

Remember: I'm not a genius too! I'm 16 years old but I know quite a lot, because Java or programming in general is fascinating me so much (and yes I have friends and other hobbies :)). So don't give up! Follow you dreams and in some day, they will get true.
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Upvoted ☝ Have a great day!

please provide a video tutorial for JDBC