Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Write this text out as a triangle

  Asked By: Molly    Date: Aug 26    Category: Java    Views: 2162
  

This programs job will be:

1. The user gives inn a text (String) into this program:
- Example: Test

2. Then the program will write this text out as a triangle:
- Example:

testtesttest
testtesttes
testtestte
testtestt
testestt
testtes
testte
testt
test
tes
te
t

How can i write this program.
I am new into JAVA so I have basics knowledge.

My question is what metods do I have to use ?
Do I need to use " Table " or can i do this whitout.
Or can i just use " for " loop

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Feodora Bonkob     Answered On: Aug 26

Use for loops and have a look at java.lang.String (the api documentation on
for instance http://java.sun.com ).

 
Answer #2    Answered By: Della Simpson     Answered On: Aug 26

import java.io.*;

public class TriangleString{
public static void main(String[] args){
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
while (s.length() > 0){
System.out.println(s);
s = s.substring(0, s.length()-1);
}
}catch(IOException ioe){
System.err.println("IOException: " + ioe.getMessage());
}
}

}

 
Didn't find what you were looking for? Find more on Write this text out as a triangle Or get search suggestion and latest updates.




Tagged: