Sie sind auf Seite 1von 5

SECTION CHALLENGE QUESTIONS

Looping Statements

WHAT ARE THESE?


These are the exercises that summarize the section.
When you complete all training videos, you should try to solve them all. If you can solve them, then it means “You are ready to
continue to next section”. Otherwise we recommend you to turn back and study again the related training video.

WHAT IF YOU WILL HAVE A QUESTION?


• 1st way : Then you can contact us via our email : koysel@akincitraining.com (Please don't forget to share your Udemy
username in your email)

• 2nd way : You can send message from Udemy (it can be private message or forum message)

Please do not hesitate to ask your questions to us. Be sure that we will do our best to help you as soon as possible.
SECTION CHALLENGE QUESTION #1 : Develop a program that prints the numbers like this :
1

32

456

10 9 8 7

11 12 13 14 15

21 20 19 18 17 16

22 23 24 25 26 27 28
.
.

SECTION CHALLENGE QUESTION #2 : Develop a program that prints the numbers like this :
10 9 8 7

456

32

SECTION CHALLENGE QUESTION #3 : What will be the result of this program (try to find the output without compile&run process)
public class LoopExample {
public static void main(String[] args) {
int x = 0;
while (x < 50)
do {
System.out.print(x++ + " ");
x += 20 % 15;
} while (x < 10);
x++;
}
}

SECTION CHALLENGE QUESTION #4 : What will be the result of this program (try to find the output without compile&run process)
public class LoopExample {
public static void main(String[] args) {
int y = 3;
for (int x = 0; x < 11; x++) {
if (x > 7) {
System.out.println("1st Part");
break;
}

if (x >= 2) {
System.out.println("2nd Part");
continue;
}

if (x > 9) {
System.out.println("3rd Part");
continue;
}
y+=x;
}
System.out.println(y);
}
}
ANSWER OF QUESTION #1 :
public class Exercise {
public static void main(String args[]) {

int count = 1;

for (int row = 1; row < 20; row++) {


// if it is an odd row
if (row % 2 == 1) {
for (int i = 0; i < row; i++)
System.out.print(count++ + " ");
System.out.println();
}
// else if it is an even row
else {
int temp = count + row - 1;
for (int i = 0; i < row; i++)
System.out.print(temp-- + " ");
System.out.println();
count += row;
}
}
}
}
Detailed Explanation: http://live2develop.com/java-exercise1/

ANSWER OF QUESTION #2 :
public class Exercise {
public static void main(String args[]) {

int count = 10;

for (int row = 4; row > 0; row--) {


// if it is an even row
if (row % 2 == 0) {
for (int i = 0; i < row; i++)
System.out.print(count-- + " ");
System.out.println();
}
// else if it is an odd row
else {
int temp = count - row + 1;
for (int i = 0; i < row; i++)
System.out.print(temp++ + " ");
System.out.println();
count -= row;
}
}
}
}

ANSWER OF QUESTION #3 :
0 6 12 18 24 30 36 42 48

ANSWER OF QUESTION #4 :
2nd Part
2nd Part
2nd Part
2nd Part
2nd Part
2nd Part
1st Part
4
Have you visited AKINCI Training’s blog: live2develop.com?
Join us today! :)

Das könnte Ihnen auch gefallen