java - Transforming int to char with input (edited) -
my program should transform letter letter 2 letter away it. c, b d. , can use first 10 letters in english alphabet. ('i' go 'a' , 'j' go 'b' cuz can use 10 letters.
import java.util.scanner; public class part6 { public static void main(string[] args) { scanner keyboard=new scanner(system.in); system.out.println("please enter 4 letter word uses first 10 letter on english alphabet(a,b,c,d,e,f,g,h,i,j): "); scanner keyboard=new scanner(system.in); string s1 = keyboard.next(); string s2 = "z1"; s2=s1.tolowercase(); if (s1.length() !=4) system.out.println("please enter word 4 letters"); char c1= s2.charat(0); char c2= s2.charat(1); char c3= s2.charat(2); char c4= s2.charat(3); int i1 =(int) c1; int i2= (int) c2; int i3= (int) c3; int i4= (int) c4; if(i1>96 && i1<107) // = 97 , j = 106 system.out.println(s2); else if (i2>96 && i2<107) system.out.println(s2); else if (i3>96 && i3<107) system.out.println(s2); else if (i4>96 && i4<107) system.out.println(s2); else system.out.println("wrong character using!"); } }
so new problem uhm if enter abcy or aaaq , abcy , aaaq. int not work. should ?
public static char transform(char s){ int base = s - 'a'; int increment = base + 2; int circularshiftincrement = increment % 10; int transformtocharvalue = circularshiftincrement + 'a'; return (char)transformtocharvalue; } public static void main(string[] args) { scanner scanner = new scanner(system.in); while(scanner.hasnext()){ string s = scanner.next(); char c = s.charat(0); char transformedstring = transform(c); system.out.println(transformedstring); } }
Comments
Post a Comment