i wish to print something like this
******** r
******* er
ter
uter
puter
mputer
omputer
computer
where * is a blank space for each line
i used array of strings
String []s1=new String [20]
for 5 blank spaces i used s1+" " + " "..+(5)""
then 4 blank spaces and print required charcters
i want to know how i can put it in a good logical general code

i wish to print something like this
******** r
******* er
ter
uter
puter
mputer
omputer
computer
where * is a blank space for each line
i used array of strings
String []s1=new String [20]
for 5 blank spaces i used s1+" " + " "..+(5)""
then 4 blank spaces and print required charcters
i want to know how i can put it in a good logical general code

If you use code tags when posting (even though it's not code), your spacing won't be stripped out.

[code]

// paste pattern here

[/code]

r
      er
     ter
    uter
   puter
  mputer
 omputer
computer

Use a nested for-loop:

String theWord = "computer";
int numLetters = theWord.length ();

for (int numSpaces = numLetters - 1; numSpaces >= 0; numSpaces--)
{
     // display numSpaces spaces using for-loop.
     // display last numLetters - numSpaces letters of theWord.
     // display newline.
}

i am not getting the blank space using for loop.i am worried i dont understand for properly can u please give me the entire program i will be grateful i know to print the letters but it goes left to right
r
er
ter
uter
puter
mputer
omputer
computer
i am not getting the blank spaces

i am not getting the blank space using for loop.i am worried i dont understand for properly can u please give me the entire program i will be grateful i know to print the letters but it goes left to right
r
er
ter
uter
puter
mputer
omputer
computer
i am not getting the blank spaces

Please post your results using code tags and post the program that you used to get those results. I can't give you the whole program. It's against the forum rules.

class gratefultodani
{
public static void main(String args[])
{
String s1="computer";
/*reverse*/
String s2=new StringBuffer(s1).reverse().toString();
char []s3=s2.toCharArray();
int i,j;
for(i=0;i<=7;i++)//8 characters 8th is null
{
for(j=0;j<=i;j++)
{
System.out.print(s3[j]);
}
System.out.println();
}
}
}

output
r
er
ter
uter
puter
mputer
omputer
computer
no clue about spaces; tabs,string =" ",'\0' all tried but for loop use gives me a weird output

no clue about spaces; tabs,string =" ",'\0' all tried but for loop use gives me a weird output

Code tags!

[noparse]
[code]
paste code or pattern here
[/code]
[/noparse]

class gratefultodani
{
public static void main(String args[])
{
String s1="computer";
/*reverse*/
String s2=new StringBuffer(s1).reverse().toString();
char []s3=s2.toCharArray();
int i,j;
for(i=0;i<=7;i++)//8 characters 8th is null
{
for(j=0;j<=i;j++)
{
System.out.print(s3[j]);
}
System.out.println();
}
}
}

Line 10 - Null terminator in a String is a C concept. Don't worry about it in Java.

I don't understand what your are "reversing" and why. You don't need to reverse anything. You could, of course, since there's more than one way of doing this, but you don't have to.

You should post the desired output, the actual output, and the code itself. Post ALL of this in code tags.

In your loop, there is no attempt to display a space. that's why you don't have any spaces. You don't need a character array. You have your string and that's good enough:

String theWord = "computer";
int numLetters = theWord.length ();

for (int numSpaces = numLetters - 1; numSpaces >= 0; numSpaces--)
{
     for (int i = numLetters - 1; i >= 0; i--)
     {
          System.out.print (" ");
     }
     for (int i = numSpaces; i < numLetters; i++)
     {
          System.out.print (theWord.charAt (i));
     }
     System.out.println ();
}

Edited 3 Years Ago by happygeek: fixed formatting

your code gives me space thats fine but it should reduce by 1 after every line
your program gives

r
er
ter
uter
puter

Edited 3 Years Ago by happygeek: fixed formatting

i am not able to express my desired output
i dont see it in this window the way i want
the space should reduce by 1 after every line and then print the characters

DON'T use my noparse tags. Those were there only to show you how to use code tags. Do exactly what is on the screen and nothing else.

[noparse]
[code]
// paste pattern here
[/code]
[/noparse]

Use the "Preview Post" button instead of "Submit Reply" and change as needed till it's right. Then submit your post.

Edited 3 Years Ago by happygeek: fixed formatting

My bad, I think. I'm not sure whether I made a typo before or got confused or whether I 100% understood what the goal of the program was, but if THIS is the goal:

   r
  er
 ter
uter

puter
mputer
omputer
computer

then line 6 needs to be changed to this:

String theWord = "computer";
int numLetters = theWord.length ();

for (int numSpaces = numLetters - 1; numSpaces >= 0; numSpaces--)
{
     for (int i = numLetters - 1; i >= 0; i--)
     {
          System.out.print (" ");
     }
     for (int i = numSpaces; i < numLetters; i++)
     {
          System.out.print (theWord.charAt (i));
     }
     System.out.println ();
}

for (int i = numSpaces - 1; i >= 0; i--)

Edited 3 Years Ago by happygeek: fixed formatting

Thank you very much it worked is there anything i can do in return for you vernon sir
Thank you very much it worked is there anything i can do in return for you vernon sir

You're welcome. I appreciate the offer. If you like, you can add to my reputation by clicking "Add to VernonDozier's Reputation" on any of my posts and adding a comment. That's strictly voluntary. Please mark this thread "Solved" so people know you don't need any more help and I hope to see you posting again on Daniweb.

dear vernon i did not get your message you sent when i asked what i can do for you

kindly tell me how i can express my gratititude. i read it half and marked it as solved. u were saying something about reputation please tell me how to do that

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Thanks for adding to my reputation. You only need to use code tags when you are posting code or posting a pattern that needs to leave the spacing intact. When you don't use code tags, all spacing (i.e. tabs, spaces) will be stripped. Code tags preserve the spacing. For normal English sentences, code tags should not be used.

You were close on the code tags. It's like this:

[code]

// paste code here

[/code]

Note that it is a forward slash (/), not a backslack (\). Please mark this thread solved. At the bottom of the thread, to the right of the yellow "Reply to Thread" button, you should see "Mark as Solved" in blue. Please click that text to mark the thread solved.

This article has been dead for over six months. Start a new discussion instead.