Computer Applications
Using the switch-case statement, write a menu driven program to do the following:
(a) To generate and print Letters from A to Z and their Unicode
Letters | Unicode |
---|---|
A | 65 |
B | 66 |
. | . |
. | . |
. | . |
Z | 90 |
(b) Display the following pattern using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Java
Java Conditional Stmts
ICSE 2019
94 Likes
Answer
import java.util.Scanner;
public class KnowledgeBoat
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter 1 for letters and Unicode");
System.out.println("Enter 2 to display the pattern");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
switch(ch) {
case 1:
System.out.println("Letters\tUnicode");
for (int i = 65; i <= 90; i++)
System.out.println((char)i + "\t" + i);
break;
case 2:
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++)
System.out.print(j + " ");
System.out.println();
}
break;
default:
System.out.println("Wrong choice");
break;
}
}
}
Output
![BlueJ output of Using the switch-case statement, write a menu driven program to do the following: (a) To generate and print Letters from A to Z and their Unicode (b) Display the following pattern using iteration (looping) statement: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 BlueJ output of Using the switch-case statement, write a menu driven program to do the following: (a) To generate and print Letters from A to Z and their Unicode (b) Display the following pattern using iteration (looping) statement: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5](https://cdn1.knowledgeboat.com/img/abp10/1/2019-p5_1.jpg)
![BlueJ output of Using the switch-case statement, write a menu driven program to do the following: (a) To generate and print Letters from A to Z and their Unicode (b) Display the following pattern using iteration (looping) statement: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 BlueJ output of Using the switch-case statement, write a menu driven program to do the following: (a) To generate and print Letters from A to Z and their Unicode (b) Display the following pattern using iteration (looping) statement: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5](https://cdn1.knowledgeboat.com/img/abp10/1/2019-p5_2.jpg)
Answered By
41 Likes
Related Questions
An air-conditioned bus charges fare from the passengers based on the distance travelled as per the tariff given below:
Distance Travelled Fare Up to 10 km Fixed charge ₹80 11 km to 20 km ₹6/km 21 km to 30 km ₹5/km 31 km and above ₹4/km Design a program to input distance travelled by the passenger. Calculate and display the fare to be paid.
The relative velocity of two trains travelling in opposite directions is calculated by adding their velocities. In case, the trains are travelling in the same direction, the relative velocity is the difference between their velocities. Write a program to input the velocities and length of the trains. Write a menu driven program to calculate the relative velocities and the time taken to cross each other.
Differentiate between if else if and switch-case statements
Which of the following is not true with regards to a switch statement?
- checks for an equality between the input and the case labels
- supports floating point constants
- break is used to exit from the switch block
- case labels are unique