java - How to get a range of characters? (alphabet) -
i have been working on hours , im kinda stuck....please me. im complete programming handicap. methods work fine except alphabet one.
it receive 2 characters (either upper or lower case) , return string composed of range of char values given. maintain same case (upper or lower) passed in method. if upper case , lower case char (one of each) passed method, convert upper case char lower case , use lower case range. note, range inclusive of starting char , exclusive of ending char. also, observe if starting (first) char given greater ending (second) char, example 'm' , 'h', method return empty string since there no chars in range.
can give me on how can above on alphabet method?
import java.util.*; class characteroperations { public static void run() { int number=1; scanner scanner = new scanner(system.in); while(number > 0) { system.out.println("(1) insert 1 change letter lower case value upper case value"); system.out.println("(2) insert 2 change letter upper case value lower case value "); system.out.println("(3) insert 3 alphabet method (range of 2 letters) "); system.out.println("enter number (or negative quit): "); number = scanner.nextint(); if (number == 1) { system.out.print("enter lower case letter: "); string a= scanner.next(); char letter = (char) a.charat(0); toupper(letter); } else if (number == 2) { system.out.print("enter upper case letter: "); string a= scanner.next(); char letter = (char) a.charat(0); tolower(letter); } else if (number == 3) { system.out.print("enter upper case or lower case letter: "); system.out.print("enter upper case or lower case letter: "); string a= scanner.next(); char letter1 = (char) a.charat(0); string b= scanner.next(); char letter2 = (char) b.charat(0); alphabet(letter1, letter2); } } } public static char toupper(char letter) { int rep = ((int)letter - 32); char ltr = (char)rep; system.out.println("the letter "+ ltr + " integer representation is: " + rep); return (char) ((int) letter -32); } public static char tolower(char letter) { int rep = (int)(letter + 32); char ltr = (char)rep; system.out.println("the letter " + ltr + " integer representation is: " + rep); return (char) ((int) letter + 32); } public static string alphabet( char letter1, char letter2){ int rep1 = (int)letter1; int rep2 = (int)letter2; char ltr1 = (char)rep1; char ltr2 = (char)rep2; system.out.println("the letter " + ltr1 + " integer representation is: " + rep1); system.out.println("the letter " + ltr2 + " integer representation is: " + rep2); } }
thanks!
with char can ++ next char , on.
char = 'a'; a++; // have b a++; // have c
just while loop go start end char.
Comments
Post a Comment