1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Minchanka [31]
3 years ago
15

Given an alphabet, print all the alphabets up to and including the given alphabet.

Computers and Technology
2 answers:
sergij07 [2.7K]3 years ago
6 0

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

Download java
anastassius [24]3 years ago
5 0

Answer:

Explanation:

public void printAlphabets(char c){

    String capitals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    String small = "abcdefghijklmnopqrstuvwxyz";

    if(capitals.contains(""+c)){

        for(int i=0; i<capitals.length();i++){

            if (capitals.charAt(i)!=c)

                System.out.print(capitals.charAt(i)+" ");

            else

                break;

        }// end for

        System.out.print(c);

    }else if (small.contains(""+c)){

        for(int i=0; i<small.length();i++){

            if (small.charAt(i)!=c)

                System.out.print(small.charAt(i)+" ");

            else

                break;

        }// end for

        System.out.print(c);

    }// end else if

}// end printAlphabets method

You might be interested in
Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) mus
Klio2033 [76]

Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, 20,000 element(s) must be compared.

6 0
1 year ago
How long does a baby dolphin stay with its mum
g100num [7]
The nursing usually takes up to 18 months, i.e. one year and a half.

The baby dolphin may however remain with his mum for up to 3-6 years.
5 0
3 years ago
Naynar kis dhrm se sambandhit hai​
Inessa05 [86]

Answer:

Islam dharm se sabandhit

5 0
2 years ago
Read 2 more answers
Computer security experts devote their time and energy to the protection of sensitive data and the prevention of an outside atta
Alik [6]

Answer:

Information security policy are used for the prevention of intruders hacking a network when an organization start getting IT related attacks.

Explanation:

Information security policy are used for the prevention of intruders hacking a network when an organization start getting IT related attacks.

An information security policy are set of rules/policies designed to guide employees for the protection of the security of company information and IT systems. The reasons for these policies are:

  1. It defines what is required from organization’s employees for the security of the IT systems
  2. Information security policies provide a means to secure the organization against external and internal threats
  3. Information security policies are a mechanism to for ensuring an organization’s legal and ethical responsibilities
  4. Information security policies are created to hold each employee responsible with regard to information security
4 0
3 years ago
Paul is a chemical engineer working with large storage tanks of chemicals. Working from home using a program on his computer, he
gregori [183]
A pressure regulator application on his computer or a station nearbye
7 0
3 years ago
Other questions:
  • A factory has a dedicated room just for computers. They are generally kept locked in the room and are never directly used by use
    5·2 answers
  • Chevening is looking for individuals with strong professional relationship building skills, who will engage with the Chevening c
    15·1 answer
  • What is the name for the type of flash memory that is used by mobile devices to store their apps and data?
    6·1 answer
  • The operating cost of driving include
    11·1 answer
  • Match the keyboard shortcuts to the function they perform
    10·1 answer
  • When entering data in Access if the data is entered using an Access form, that data is stored in a table or tables. TRUE FALSE
    12·1 answer
  • What is the purpose of a report?
    12·2 answers
  • How does social network use message to entertain?
    14·1 answer
  • Besides your computer, where else can you find and use an operating system?
    11·1 answer
  • A(n) ________ address is the address that external entities use when communicating with your network.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!