10082 - WERTYU

Problem Link

Caranya sangat senang iaitu dengan menggunakan  "if-else" statement. Sebagai contoh jika huruf 'S' di masukkan, maka ianya akan keluarkan output 'A'. Yang penting jangan lupa letak 'space' sekali.

Solution :

import java.util.*;
public class uva10082 {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
while(scn.hasNextLine()) {
String s = scn.nextLine();
for(int x=0;x<s.length();x++) {
char c = s.charAt(x);
if(c == 'W')
System.out.print('Q');
else if(c == ' ')
System.out.print(' ');
else if(c == 'E')
System.out.print('W');
else if(c == 'R')
System.out.print('E');
else if(c == 'T')
System.out.print('R');
else if(c == 'Y')
System.out.print('T');
else if(c == 'U')
System.out.print('Y');
else if(c == 'I')
System.out.print('U');
else if(c == 'O')
System.out.print('I');
else if(c == 'P')
System.out.print('O');
else if(c == '[')
System.out.print('P');
else if(c == ']')
System.out.print('[');
else if(c == '\\')
System.out.print(']');
else if(c == 'S')
System.out.print('A');
else if(c == 'D')
System.out.print('S');
else if(c == 'F')
System.out.print('D');
else if(c == 'G')
System.out.print('F');
else if(c == 'H')
System.out.print('G');
else if(c == 'J')
System.out.print('H');
else if(c == 'K')
System.out.print('J');
else if(c == 'L')
System.out.print('K');
else if(c == ';')
System.out.print('L');
else if(c == '\'')
System.out.print(';');
else if(c == 'X')
System.out.print('Z');
else if(c == 'C')
System.out.print('X');
else if(c == 'V')
System.out.print('C');
else if(c == 'B')
System.out.print('V');
else if(c == 'N')
System.out.print('B');
else if(c == 'M')
System.out.print('N');
else if(c == ',')
System.out.print('M');
else if(c == '.')
System.out.print(',');
else if(c == '/')
System.out.print('.');
else if(c == '1')
System.out.print('`');
else if(c == '2')
System.out.print('1');
else if(c == '3')
System.out.print('2');
else if(c == '4')
System.out.print('3');
else if(c == '5')
System.out.print('4');
else if(c == '6')
System.out.print('5');
else if(c == '7')
System.out.print('6');
else if(c == '8')
System.out.print('7');
else if(c == '9')
System.out.print('8');
else if(c == '0')
System.out.print('9');
else if(c == '-')
System.out.print('0');
else if(c == '=')
System.out.print('-');
}
System.out.println("");
}
}
}

Share this

Related Posts

Previous
Next Post »