I need to create a certain SHAPE with FOR LOOP.
This was the proposed output:
Code :
************
************
************
************
************
************
************
************
i cant do it purely with for loop i dont know if im missing something :)
Code :
public class Loop {
public static void main(String[] args) {
for (int i = 1; i <= 8; i++) {
switch(i){
case 2:
System.out.print(" ");
break;
case 4:
System.out.print(" ");
break;
case 6:
System.out.print(" ");
break;
case 8:
System.out.print(" ");
break;
}
for (int j = 0; j < 12; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
Anyone else have other methods just only using forloop? please be humble with me its my first time asking a community :D im nervous.
Re: I need to create a certain SHAPE with FOR LOOP.
Quote:
Originally Posted by
Rage1337
This was the proposed output:
Code :
************
************
************
************
************
************
************
************
i cant do it purely with for loop i dont know if im missing something :)
Code :
public class Loop {
public static void main(String[] args) {
for (int i = 1; i <= 8; i++) {
switch(i){
case 2:
System.out.print(" ");
break;
case 4:
System.out.print(" ");
break;
case 6:
System.out.print(" ");
break;
case 8:
System.out.print(" ");
break;
}
for (int j = 0; j < 12; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
Anyone else have other methods just only using forloop? please be humble with me its my first time asking a community :D im nervous.
Hiya,
is this answer too obvious?
Code Java:
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i=0; i<5; i++){
if (i % 2 == 0)
System.out.println(" ************");
else
System.out.println("************");
}
}
regards,
Kevin.
Re: I need to create a certain SHAPE with FOR LOOP.
Thank you bro, maybe this was the solution my professor was looking because he told me my code was too long. any other methods tho??
Re: I need to create a certain SHAPE with FOR LOOP.
Actually Kevin the for loop should have the statement like this i<8.So the answer is(basically what Kevin said,only a number changed)
Code :
public static void main(String[] args) {
for (int i = 0; i < 8; i++) {
if (i % 2 == 0) {
System.out.println(" ************");
} else {
System.out.println("************");
}
}
}
Re: I need to create a certain SHAPE with FOR LOOP.
Quote:
Originally Posted by
Rage1337
Thank you bro, maybe this was the solution my professor was looking because he told me my code was too long. any other methods tho??
Another method based to kevin's answer is this:
Code :
public static void main(String[] args) {
for (int i = 0; i < 8; i++) {
if (i % 2 == 0)
System.out.print(" ");
System.out.println("************");
}
}
Re: I need to create a certain SHAPE with FOR LOOP.
Quote:
Originally Posted by
Samaras
Another method based to kevin's answer is this:
Code :
public static void main(String[] args) {
for (int i = 0; i < 8; i++) {
if (i % 2 == 0)
System.out.print(" ");
System.out.println("************");
}
}
Good One tho ive got some ideas of what you did. anyways your output was the other way around :) spaces should be in the second 4th 6th and 8th line.
Re: I need to create a certain SHAPE with FOR LOOP.
Ok,you see what has to be changed.And my list and most simple idea is this
Code :
public static void main(String[] args) {
for (int i = 0; i < 4; i++) {
System.out.println("************");
System.out.println(" ************");
}
}
Re: I need to create a certain SHAPE with FOR LOOP.
Everyone contributing to this thread should read the following:
http://www.javaprogrammingforums.com...n-feeding.html
Original poster, I do hope you fully understand these handouts, as well as fully understand the academic policy of the school you attend (you mention professor, so I assume this is an assignment)
Re: I need to create a certain SHAPE with FOR LOOP.
I am aware of this acts, that lab exercise is already done , and as far as im concerned i was just asking for alternatives, sorry for that.