-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaArray04.txt
More file actions
27 lines (24 loc) · 929 Bytes
/
JavaArray04.txt
File metadata and controls
27 lines (24 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*Task 4
Write a Java program that takes a string input in small letters from the user and prints the previous alphabet in sequence for each alphabet found in the input.
Sample Input Output
wxyz vwxy
thecow sgdbnv
abcd zabc */
import java.util.Scanner;
public class JavaArray04{
public static void main(String [] args){
Scanner sc= new Scanner(System.in);
String st1=sc.nextLine();
String emp="";
for(int i=0;i<st1.length();i++){
char ch=st1.charAt(i);
if(ch=='a'){
ch='z';
emp+=ch;}
else{
int val=(int) ch;
ch=(char)(val-1);
emp+=ch;}}
System.out.println(emp);
}
}