how can i achieve this?

# # # # # # # ## # # # # # # ## # # # # # # ## # # # # # # # # # # # # # ## # # # # # # # ### # # # # ## # # # # # #### # # # ## # # # ## ### # # ## # # ## ## # # ## # ##### ## ## ## ### # # # # # # ## # # # # # # #?
[279 byte] By [schumachera] at [2007-11-27 8:13:59]
# 1
System.out.println
ByronTheOmnipotenta at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 2
By writing code. When you're done, let us know.
floundera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 3
> System.out.printlnThere you go Byron, you can taunt people too.
floundera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 4
http://imagetiki.com/uploads/8cfba6456e.pngnow thats taunting flounder :)Message was edited by: ByronTheOmnipotent
ByronTheOmnipotenta at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 5
BTW schumacher, if you have a specific question, post it. Currently you post is "I wanna learn how to build a space shuttle. Can you show me how?"
floundera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 6

Thanks for all the help you have given me so far. i am able to print the # but my problem was the tabbing i tried different solutions but its going to different line rather than staying on the same line. for example

public class StarProgram {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

for(int i=1; i<=8; i++) {

//System.out.print('#');

for(int j=1; j<=8-i; j++)

System.out.print('#');

System.out.println();

}

}

}

output

#######

######

#####

####

###

##

#

I know its a little bit of math to just print the other way i can do that but tabbing is my main problem and the last two design which is

******************

*******

*****

something like this which i posted earlier is where i will be struggling. any ideas or clues? that is all i am asking.

schumachera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 7
u know if u copy each line of what u wanted to print it and put it into println(""); it would work with the spacing, thats what i did and its real ezwoops i didnt see that you wanted to do it with mathMessage was edited by: ByronTheOmnipotent
ByronTheOmnipotenta at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 8
You can use \t to tab.If things are not appearing on the same line then you have a println call in the wrong place.
floundera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 9
yea i know :) i wish i dont have to use for loops. but had to do it.. that tabbing part is really messing me up. i mean will take bunch of for loops and what kind of exercise is this. give me something entering data storing it in a file rather than asking me to printing #. o well lets see
schumachera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 10

> u know if u copy each line of what u wanted to print

> it and put it into println(""); it would work with

> the spacing, thats what i did and its real ez

>

> woops i didnt see that you wanted to do it with math

>

> Message was edited by:

> ByronTheOmnipotent

So I guess if your teacher asked you to print the value 2 cubed this would be your answer:

System.out.println(8);

Gold star for you.

floundera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 11

i tried 4 for loops one in another but output is totally different. yes i know how to use tab

System.out.print("\t"); i tried but output is different let me think a little harder. may be a beer will work for me at this moment.

How many for loops do you think i need to use ? and what kind of math i can use for the last 2 # design

schumachera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 12

> yea i know :) i wish i dont have to use for loops.

> but had to do it.. that tabbing part is really

> messing me up. i mean will take bunch of for loops

> and what kind of exercise is this. give me something

> entering data storing it in a file rather than asking

> me to printing #. o well lets see

Another piece of advice, all your code doesn't have to be in the main method. Think about how you can write 1, 2 or more other methods that you can call from within a loop to aid you.

floundera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 13

> > yea i know :) i wish i dont have to use for loops.

> > but had to do it.. that tabbing part is really

> > messing me up. i mean will take bunch of for loops

> > and what kind of exercise is this. give me

> something

> > entering data storing it in a file rather than

> asking

> > me to printing #. o well lets see

>

> Another piece of advice, all your code doesn't have

> to be in the main method. Think about how you can

> write 1, 2 or more other methods that you can call

> from within a loop to aid you.

hmmmm good genuine advice.. Let me try

schumachera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 14

ok a little object oriented way.

public class StarProgram {

private static final String TAB = "\t";

/**

* @param args

*/

public static void main(String[] args) {

StarProgram star = new StarProgram();

System.out.print(star.printPound() + TAB + star.printPound());

}

public StarProgram() {

//default constructor

}

public String printPound() {

String r = "";

for(int i=1; i<=8; i++) {

for(int j=1; j<=i; j++)

r = r+"#";

r = r+"\n";

// System.out.print(r);

//System.out.println();

}

return r;

}

}

so i was just testing to see the TAB works or not. it should print one set of # and the other one after a space. but for some reason it outputs this

#

##

###

####

#####

######

#######

########

#

##

###

####

#####

######

#######

########

schumachera at 2007-7-12 19:58:29 > top of Java-index,Java Essentials,New To Java...
# 15
>So I guess if your teacher asked you to print the value 2 cubed this would be >your answer:>>System.out.println(8);>>>Gold star for you.and thats wrong? lol
ByronTheOmnipotenta at 2007-7-21 22:33:24 > top of Java-index,Java Essentials,New To Java...
# 16
> Gold star for you.u bad man starist
cotton.ma at 2007-7-21 22:33:24 > top of Java-index,Java Essentials,New To Java...
# 17
question. how can i remove # ? like i would like to print# # # # # # # # # # # # # ## # # # # # # # # # # ## # #so if use a for loop then i would like to remove the # when it reaches the loop second time.
schumachera at 2007-7-21 22:33:24 > top of Java-index,Java Essentials,New To Java...
# 18

So now instead of having all your code in the main method you basically have it inside the printpound method. Have a look at this, it doesn't do what you want exactly but it should give you an idea.

class Stars {

public static void main(String[] args) {

int spaces = 5;

for(int index = 1; index <= 5; index++) {

printchars(index, '*');

printchars(spaces, ' ');

printchars(Math.abs(spaces - index), '*');

System.out.println();

spaces--;

}

}

public static void printchars(int num, char c) {

for(int index = 0; index < num; index++) {

System.out.print(c);

}

}

}

floundera at 2007-7-21 22:33:24 > top of Java-index,Java Essentials,New To Java...
# 19
for(int i=0; i<=8;i++)for(int i=8;i>=0;i--)
cotton.ma at 2007-7-21 22:33:25 > top of Java-index,Java Essentials,New To Java...
# 20

thanks flounder. so that means i need to use Math.abs(i-j) in order for the tabbing. hmmm. after looking at your code and trying to implement it my way i came out with this method for the first # design.

# # # # # # # #

# # # # # #

# # # # #

# # # #

# # #

# #

#

This is what i wrote

public void printPound() {

for(int i=1; i<10; i++) {

for(int j=1; j<i; j++)

System.out.print(".");

for(int z=1; z><10-i; z++)

System.out.print("#");

System.out.println();

}

}

it prints this

########

.#######

..######

...#####

....####

.....###

......##

.......#

so like cotton suggested a for loop but that does not make any sense since it is going to delete my entire #. Let me ask from the instructor if he really wants me to do it using tabbing or if i can print each # design on a new line which will be efficient for me.

schumachera at 2007-7-21 22:33:25 > top of Java-index,Java Essentials,New To Java...
# 21

> so that means i need to use Math.abs(i-j) in order for the tabbing. hmmm.

No! I only used that to ensure I got a postive number. The whole point of my code was to illustrate how you can use a second method. All it does is take a char and the number of times it has to print. Thats it. Then elsewhere you need to implement logic that determines what char to print when and how many times.

floundera at 2007-7-21 22:33:25 > top of Java-index,Java Essentials,New To Java...
# 22

you damnnnn right. I got the first 2 # design.

public class StarProgram {

private static final String TAB = "\t";

/**

* @param args

*/

public static void main(String[] args) {

StarProgram star = new StarProgram();

star.printPound();

System.out.println();

star.printSecondPound();

}

public StarProgram() {

//default constructor

}

public void printPound() {

char c = ' ';

for(int i=1; i<10; i++) {

for(int j=1; j<i; j++)

System.out.print(c);

for(int z=1; z><10-i; z++)

System.out.print("#");

System.out.println();

}

}

public void printSecondPound() {

String c ="" ;

for(int i=1; i<10; i++) {

for(int j=1; j<i; j++)

System.out.print(c);

for(int z=1; z><10-i; z++)

System.out.print("#");

System.out.println();

}

}

}

Output

########

#######

######

#####

####

###

##

#

########

#######

######

#####

####

###

##

#

I know its on different line but glad to achieve the first 2 # design. Thanks all. i will post back if i get stuck in the 3rd and 4th. Dukes for you flounder.

schumachera at 2007-7-21 22:33:25 > top of Java-index,Java Essentials,New To Java...