hi,
i am trying to write a programme that reads in a word, and outputs the last charecter, then the last two then the last three and so on
e.g
input: java
output: a, va, ava, java
i have written the code but my loop is backward, insteed of reading the last character first, it will start with the first one
e.g
input: java
output: j, ja, jav, java
here is my code, any help would be greatly appreciated
Quote:
package Loop;
import java.util.Scanner;
public class loop {
public static void main(String[] args) {
String word;
String output = "";
Scanner scan = new Scanner(System.in);
System.out.println("Enter a string: ");
word = scan.next();
int numbers = word.length();
for (int i = 0; i < numbers; i++)
{
output += word.substring(0, i + 1) + ",";
}
System.out.println(output + "\n");
}
