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

This is Eclipse Java Can someone please solve this Eclipse SwapStarsTabs questio

ID: 3800257 • Letter: T

Question

This is Eclipse Java

Can someone please solve this Eclipse SwapStarsTabs question for me? I am having a hard time with it, thanks!

Write a program that converts all TABS in your code (i.e. the ' ' character) with STARS (i.e. the '*' character and all STARS in your code to TABS.

Input The input will be one or more lines of characters that have been typed in by the user.

Output The output will be exactly the same as the input EXCEPT that all tabs would have been converted to stars and all stars would have been converted to tabs.

Sample Input (TABS are shown by underlining here) _34682**43.3*4234___hhhh**dsfd **** fsfsfdsfsfsd fs _ _ _ _ _ _ _ _ _ _ _ _******_ _ _ _ _ _ jsadg * jsdg dg * ad * asd asjd_df sdgf sdgfs f

Sample Output *34682__43.3_4234***hhhh__dsfd ____ fsfsfdsfsfsd fs * * * * * * * * * * * *______* * * * * * jsadg _ jsdg dg _ ad _ asd asjd_df sdgf sdgfs f NOTE There were some tabs without spaces between them – and some with spaces between them. That’s why some *'s have no spaces between them and some have. You can enter a TAB character by pressing the tab key

HINT You need to first convert all tabs in a line to some thing else – like say newline or ' '. Then convert all stars in the line to tabs. Then convert all ' ' in the line to stars.

Explanation / Answer

for this we will use the java replace function.

The java string replace() method returns a string replacing all the old char or CharSequence to new char or CharSequence.

syntax - public String replace(char oldChar, char newChar)

now, first replace ALL tabs with random char (' ' for instance) this way we can then replace '*' with ' ' without risking duplication, then change ' ' to '*'

-------------------------------------------------------------------------------

code

             s = s.replace(' ',' ');

             s=s.replace('*',' ');

             s=s.replace(' ','*');

            System.out.println(s);

}

}

--------------------------------------

thank you

          

         

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