# [SOLVED] java programming trouble



## raident30 (Jun 8, 2009)

how do i write a program that lets the user input a string of 10 characters(strings/numbers) and that the program should output the following pattern?

ex. A1B2C3D4E5

output:
A1B2C3D4E5
A1B2C3D4E
A1B2C3D4
A1B2C3D
A1B2C3
A1B2C
A1B2
A1B2
A1
A

someone told me that i need to use loops to run this program but well im still studying loop and i have no idea how to do this... thanks for those who will help..


----------



## raident30 (Jun 8, 2009)

*Re: java programming trouble*

i got a simple code to do it but i dont know how to prompt with loops..


```
import java.util.*;
public class NestedLoop
{

	public static void main(String[] args)
	{
		int i;
		int j;

		for(i = 5; i >= 1; i--)
		{
		for (j = 1; j <= i; j++)
		System.out.print("*");
		System.out.println();
		}
	}
}
```


----------



## Special2God (Oct 5, 2009)

*Re: java programming trouble*



raident30 said:


> ... i dont know how to prompt with loops..


What do you mean? 
Collecting user input is as simple as: 

```
// Slightly edited version of your code:

import java.util.*;
public class Test {

	public static void main(String[] args) {
		Scanner userKeyboard = new Scanner(System.in);
		String input = userKeyboard.nextLine();

		// notice how the counter starts at input.length() which is a string method that returns the length of the string
		for(int i = input.length(); i > 0; i--) {
			for (int j = 0; j < i; j++)
			// you can use .charAt(int x) to print a specific element in a String
			System.out.print( input.charAt(j) );
		System.out.println();
		}
	}
}
```
Is this what you want to do..?


----------



## raident30 (Jun 8, 2009)

*Re: java programming trouble*

sir you got it! thats what im looking for! thanks sir, you always answer all of my java problems!


----------



## Ninjaboi (Dec 27, 2010)

*Re: java programming trouble*



raident30 said:


> sir you got it! thats what im looking for! thanks sir, you always answer all of my java problems!


Did Special2God's answer solve your problem? If so, glad it's been sorted out for you :smile:. Please mark this thread "Solved" if your question has been solved.


----------



## raident30 (Jun 8, 2009)

*Re: java programming trouble*

yes he did! thanks!


----------

