Computer Applications
Using the switch statement in Java, write a program to display the colour of the spectrum (VIBGYOR) according to the user's choice.
Java
Java Conditional Stmts
101 Likes
Answer
import java.util.Scanner;
public class KboatSpectrum
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("VIBGYOR Spectrum");
System.out.println("Enter your colour choice: ");
char choice = in.next().charAt(0);
switch (choice) {
case 'V':
System.out.println("Violet");
break;
case 'I':
System.out.println("Indigo");
break;
case 'B':
System.out.println("Blue");
break;
case 'G':
System.out.println("Green");
break;
case 'Y':
System.out.println("Yellow");
break;
case 'O':
System.out.println("Orange");
break;
case 'R':
System.out.println("Red");
break;
default:
System.out.println("Incorrect choice");
}
}
}
Output

Answered By
49 Likes
Related Questions
Write the following switch statement by using nested if statements:
switch (choice) { case 0: case 1: x = 11; y = 22; break; case 2: x = 33; y = 44; break; default: y = 55; break; }
Write an if statement to find the smallest of the three given integers using the min() method of the Math class.
Employees at Arkenstone Consulting earn the basic hourly wage of Rs.500. In addition to this, they also receive a commission on the sales they generate while tending the counter. The commission given to them is calculated according to the following table:
Total Sales Commmision Rate Rs. 100 to less than Rs. 1000 1% Rs. 1000 to less than Rs. 10000 2% Rs. 10000 to less than Rs. 25000 3% Rs. 25000 and above 3.5% Write a program in Java that inputs the number of hours worked and the total sales. Compute the wages of the employees.
Write a program in Java to compute the perimeter and area of a triangle, with its three sides given as a, b, and c using the following formulas: