undefined

For loop in practice

Java Syntax
Level 4 , Lesson 13
Available

"Today is my lucky day. I came up with five new tasks for you. I'm brimming with creativity. Good luck, my friend. You will need it..."

undefined
2
Task
Java Syntax, level 4, lesson 13
Locked
Even numbers
A for loop simplifies the counting, simplifies displaying text, and simplifies... the life of a programmer! And it saves a lot of time: just a couple of simple lines of code and you can display every even number from 1 to 100 inclusive. Let's try it, but be sure to put each value on a separate line.
undefined
4
Task
Java Syntax, level 4, lesson 13
Locked
Drawing a rectangle
Expressive drawing using the modest tools of pseudographics is the same as minimalism in music. At least, some critics on Earth think so. Well, let's heed their words and do some drawing. Let's enter two numbers m and n, and draw a rectangle of eights. The rectangle will be m eights high and n eights wide.
undefined
4
Task
Java Syntax, level 4, lesson 13
Locked
Triangle of eights
Drawing on the console is called "pseudographics". This technique began at the dawn of the computer age and progressed in parallel with ordinary graphics until the beginning of the Windows era. Then it stagnated and faded away. Maybe you daydream about great pseudographics? Let's start mastering the technique by drawing a "triangle of eights".
undefined
2
Task
Java Syntax, level 4, lesson 13
Locked
Drawing lines
Everything starts with lines, including the path of an artist. But the path of a programmer begins with the study of loops. At this point, we need to master the for loop. It is convenient, simple, and helps us create. Let's use it to draw horizontal and vertical lines, consisting of ten 8s each.
undefined
2
Task
Java Syntax, level 4, lesson 13
Locked
Chain letter
Who (or for some people, what) do you see in your sweet dreams? Do you have someone in mind? Make a wish. Write a program that takes a name from the keyboard and displays the phrase " loves me" 10 times. If you do this with a for loop, your wish* will come true (*your wish to become a programmer).
Comments (38)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Jurij Thmsn Level  14, Flensburg, Germany
12 December 2020
Spend more time on " drawing lines" than on all the other tasks combined. don't get confused like me and use int = 0 in the loops, not int =1 ;-)
Kelly Pepper Level  7, Orlando, United States
18 October 2020
Really fun to see "My cat loves me" 10 times :)
Joe M Level  9, East Coast, United States
29 September 2020
"fori"+ TAB sets up a "for" loop in IJ
Agent Smith Level  38
9 August 2020
One more thing: you can declare several variables inside for loop and use several increments:

        for (int i = 1, j = 1; i < 10 && j < 100; i++, j *= i) {
            // body
        }
Attila Level  7, Hainault, United Kingdom
4 July 2020
look for java pattern if you really would like to understand, looks like not so difficult but more mathematical logic.
Wilson Meals Level  4, Garešnica, Croatia
29 December 2019
I will never understand building those "8" pyramids. I have no idea why my code works. I was simply lucky.
hidden #10410956 Level  6
28 August 2019
enjoy it!! are you?
Gabriella LaPlace Level  16, Basseterre, Saint Kitts and Nevis
29 July 2019
Some of these exercises were tough to me but I got help in the Help section.
Turner Level  11, Pittsburgh, United States
19 July 2019
Thanks for returning to the convention of showing example program output. It doesn't help to have vague requirements simply to have vague requirements. No programming assignment I've had EVER does that. Please correct the oversight in "Drawing Lines".
Abdur Rehman Level  7, Faisalabad, Pakistan
12 May 2019
sub to pewds