Computer Science, asked by siddharthgager30, 8 months ago

write a program that reads a string and then print it a follows:-
input string:- this is a pen
output string :- uijt$jt$jtb$b$qfo

please dont anwser worng this question is not present on web if you give correct answer I will definitely thanks your all question and mark u you as brainliest​

Answers

Answered by anindyaadhikari13
3

\star\:\:\:\sf\large\underline\blue{Question:-}

Write a program in java that reads a string and then it print is as follows.

Input String:- this is a pen

Output:- uijt$jt$b$qfo

\star\:\:\:\sf\large\underline\blue{Logic:-}

Character after t = u

Character after h = i

Character after i = j

Character after s = t

Now, space is replaced by dollar.

We shall use this logic to solve the problem.

Now, a problem arises,

If the character is z then the next character '~' will be printed.

We can replace ~ with a.

\star\:\:\:\sf\large\underline\blue{Source\:Code:-}

class StringProgram

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the String: ");

String s=sc.nextLine();

String n="";

int len=s.length();

for(int i=0;i<len;i++)

{

char ch=s.charAt(i);

if(ch==' ')

ch='$';

else if(ch=='z')

ch='a';

else if (ch=='Z')

ch='A';

else if(ch>='a' && ch <'z' && ch>='A' && ch<'Z')

ch++;

n=n+ch;

}

System.out.println("New String: "+n);

}

}

Similar questions