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 i have mixed up my loop, 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 advice where i have gone wrong would be greatly appreciated
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"); } }