Answer:
//Write the printAlphaber method header;
//It takes a char as parameter and has a return type of void
public static void printAlphabet(char ch){
//Every char has its ASCII number representation
//For example, char 'A' = 65, 'B' = 66, 'a' = 97, 'c' = 99
//In essence, A to Z = 65 to 90 and a to z = 97 to 122
//Also, if comparing a char with an int will compare the ASCII representation of the char with the int
//For example, 'A' == 65 will return true.
//Using this technique, let's write an if..else statement that checks
//if char ch is between 65 and 90 both inclusive.
//If ch is between 65 and 90, then it is an uppercase letter
if(ch >= 65 && ch <=90){
//Therefore, write a for loop to print all capital letters from 65(which is A) to char
//starting from i=65 and ending at i=ch
for(int i = 65; i <= ch; i++){
//print the char representation of the ASCII number
//by type casting the ASCII number to a char
System.out.print((char)i);
//attempt to print a space char if i is not the last letter in the sequence
if (i != ch){
System.out.print(" ");
}
}
}
//If ch is between 97 and 122 both inclusive, then it is a lowercase letter
else if(ch >= 97 && ch <= 122){
//Therefore, write a for loop to print all capital letters from 97(which is a) to char
//starting from i=97 and ending at i=ch
for(int i = 97; i <= ch; i++){
//print the char representation of the ASCII number
//by type casting the ASCII number to a char
System.out.print((char)i);
if (i != ch){
System.out.print(" ");
}
}
}
else{
System.out.println("");
}
} // End of method printAlphabet
<h2>
Sample Output:</h2>
<em><u>When printAlphabet is called with d i.e printAlphabet('d')</u></em>
>> a b c d
<em><u>When printAlphabet is called with K i.e printAlphabet('K')</u></em>
>> A B C D E F G H I J K
<h2>
Explanation:</h2>
The code above has been written in Java and it contains comments explaining every segment of the code. Please kindly read the comments carefully. The source code file for the complete application has been attached to this response. Kindly download it.
<u><em>The code without comments</em></u>
public static void printAlphabet(char ch){
if(ch >= 65 && ch <=90){
for(int i = 65; i <= ch; i++){
System.out.print((char)i);
if (i != ch){
System.out.print(" ");
}
}
}
else if(ch >= 97 && ch <= 122){
for(int i = 97; i <= ch; i++){
System.out.print((char)i);
if (i != ch){
System.out.print(" ");
}
}
}
else{
System.out.println("");
}
} // End of method printAlphabet