answersLogoWhite

0

How do I reverse a String and at the same time delete one letter (until all what's left is a single letter) using loops (JAVA)?

Hello! I'm kinda new to programming so here's my problem. How can I reverse a String and then at the same time make the last letter deleted using a loop until all what's left is a single letter. For example: User inputs "programming" The code should loop the input deleting one letter at a time (while reversed) What should be the output is something like this: gnimmargorp gnimmargor gnimmargo gnimmarg gnimmar gnimma gnimm gnim gni gn g How can I make it done like that? Please help thanks alot!

User Avatar

joonthemoon999

Lvl 1
3y ago
Updated: 3/25/2022

I have some knowledge of programming but I'm unsure of anything in java, my explanation is created out of my understanding of JavaScript. I will try to express variables within parenthesis ()

Reversing The Input (assuming you know how to retrieve user input)

My suggestion is to create a variable named (i) and set it to the length of a variable called (string),// the user's input //, and create a loop repeating length of (string) times, where each time through variable (i) changes by - (1), and join letter (i) of (string) to a new variable (reversed_string), and you have the reversed the string.

Taking away last letter each time


Reposted, if image doesn't show I'll try to explain it. The code is based on JavaScript language

Code
User Avatar

Jigosphur

Lvl 8
3y ago

What else can I help you with?

Related Questions

How do you delete a single text on your iPhone?

to delete a single text withing a string of text messages click the "edit" button in the string and select and delete


Program to reverse string in perl?

To reverse a string in Perl, you can use the reverse function along with split to break the string into individual characters, and then join them back together. Here’s a simple example: my $string = "Hello, World!"; my $reversed = join('', reverse split('', $string)); print $reversed; # Output: !dlroW ,olleH This code splits the string into characters, reverses the list of characters, and then joins them back into a single string.


String reverse program with single string and without using library functions in java?

You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.


How do you delete a WolfQuest profile?

On single player you go onto single player then click on the saving you wanna delete then select delete or if you mean on the forums you ask a moderator to delete it for you. hope this helps :)


How does perl interpretor know that string has ended?

A Perl string begins and ends with a delimiter. This can either be a single-quote ('), double-quote (") or user defined quote (q): $single = 'This string is single-quoted'; $double = "This string is double-quoted"; $user = q^This string is delimited by the caret symbol^


Do single quoted string literals have any characteristics difference from those of double quoted string literals?

Yes. A single-quoted literal must be a valid character (byte or char) type. It is not a String type. There is no such thing as a single-quoted String literal. 'A' - evaluates to the primitive char type "A" - evaluates to a String type 'ABC' - causes compiler error because it isn't a single character


What is a data string?

A data type consisting of more than one letter, like a word or a sentence. A single letter is normally known as a character data type. Normally strings are enclosed in double quotation marks and single letters are enclosed in single quotations marks: 'a' "animal"


What is the algorithm for reverse a given number recursively?

//Function that reverses a given number int reverse(int num) { static int sum,base =1; sum=0; if(num>0) { reverse(num/10); sum += (num%10)*base; base*=10; } return sum; }


How do you reload a single string weedeater?

pop the spool out wind string in direction of arrow, replace


Which function joins one string with another to produce single string that contains both?

strcat()


Delete single calls on iPhone for free?

Yes


Can be a single character word or phrase in a cell?

string