answersLogoWhite

0


Best Answer

Let's say you want a method which will determine if the given character is a vowel, consonant, or other (non-letter).

// Will return a String representation of what the given character is:

// "vowel" "consonant" or "other"

public static final String getTypeOfChar(final char c) {

// since chars are an integer data type in Java, we can switch on them

switch(c) {

case 'a': // all of these cases "fall through" to the next non-case statement

case 'e': // if any of them matches

case 'i':

case 'o':

case 'u':

return "vowel";

case 'b': // again, all of these cases fall through

case 'c':

case 'd':

case 'f':

case 'g':

case 'h':

case 'j':

case 'k':

case 'l':

case 'm':

case 'n':

case 'p':

case 'q':

case 'r':

case 's':

case 't':

case 'v':

case 'w':

case 'x':

case 'y':

case 'z':

return "consonant";

default: // if we have no matches yet, do this

return "other";

}

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago


2. Write a program using switch statement that reads a character representing a geometrical figure, then asks the user to enter the required data (ex. Radius for a circle, length and height for a rectangle, etc. ...) . The program should then print the area and circumference.
Figures are: circle(c), square(s), rectangle(r), triangle (t).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a java program using switch case to find zodiac signs?
Write your answer...
Submit
Still have questions?
magnify glass
imp