Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this task you will create a program that prints out a user - specified strin

ID: 3564537 • Letter: F

Question

For this task you will create a program that prints out a user - specified string. Then, on the next line, it prints out the string again, all except the last character. It continues printing the stringwith one less character on each line, until the last line has only the first character of the string.

Name your class "CharacterCountdown"

Read an entire line, rather than just a word. You'll need to usenextLine(), from the Scanner class.

Use a single while loop in this program.

You'll probably want to use substring(), from the String class.

Explanation / Answer

import java.util.Scanner;

public class CharacterCountdown {

   public static void main(String[] args) {
       String str;
       int length;
       System.out.print("Enter a String: ");
       Scanner input = new Scanner(System.in);
str = input.nextLine();
length = str.length();
while(length>=0)
{
   System.out.println(str.substring(0,length));
   length--;
}
   }

}

Output:
Enter a String: Naveen
Naveen
Navee
Nave
Nav
Na
N

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote