if-else-if ladder: Here, a user can decide among multiple options.The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.
if (condition) statement; else if (condition) statement; . . else statement;
<------------------------------------------------------------------------------------------------------------------------------------------------->
switch-case The switch statement is a multiway
branch statement. It provides an easy way to dispatch execution to
different parts of code based on the value of the expression.
Syntax:
switch (expression) { case value1: statement1; break; case value2: statement2; break; . . case valueN: statementN; break; default: statementDefault; }
<--------------------------------------------------------------- Program----------------------------------------------------------------------->
import java.io.*;
class Sm
{
public static void main(String args[]) throws
IOException
{ int m;
System.out.println("Enter your
month ");
DataInputStream d= new
DataInputStream(System.in);
m=Integer.parseInt(d.readLine());
switch(m)
{
case 1:
System.out.println("You entered Janaury ");
System.out.println("It's abbreviation is Jan ");
System.out.println("This is month number "+m);
break;
case 2:
System.out.println("You entered February ");
System.out.println("It's abbreviation is Feb ");
System.out.println("This is month number "+m);
break;
case 3:
System.out.println("You entered March ");
System.out.println("It's abbreviation is March ");
System.out.println("This is month number "+m);
break;
case 4:
System.out.println("You entered April ");
System.out.println("It's abbreviation is April ");
System.out.println("This is month number "+m);
break;
case 5:
System.out.println("You entered May ");
System.out.println("It's abbreviation is May ");
System.out.println("This is month number "+m);
break;
case 6:
System.out.println("You entered June ");
System.out.println("It's abbreviation is June ");
System.out.println("This is month number "+m);
break;
case 7:
System.out.println("You entered July ");
System.out.println("It's abbreviation is July ");
System.out.println("This is month number "+m);
break;
case 8:
System.out.println("You entered February ");
System.out.println("Is abbreviation is Feb ");
System.out.println("This is month number "+m);
break;
case 9:
System.out.println("You entered February ");
System.out.println("It's abbreviation is Feb ");
System.out.println("This is month number "+m);
break;
case 10:
System.out.println("You entered October ");
System.out.println("It's abbreviation is Oct ");
System.out.println("This is month number "+m);
break;
case 11:
System.out.println("You entered Novmber ");
System.out.println("It's abbreviation is NOv ");
System.out.println("This is month number "+m);
break;
case 12:
System.out.println("You entered December ");
System.out.println("It's abbreviation is Dec ");
System.out.println("This is month number "+m);
break;
default:
System.out.println("This is wrong
Entry ");
}
}
}
<----------------------------------- Output is --------------------------------------------------------------------->
Write the class SwitchingUpMonths.java. This program will be completing exactly the same task as Lab3c, however...
using python Write a program that asks the user to enter a month (1 for January, 2 for February, and so on) and then prints the number of days in the month. For February, print “28 or 29 days”. Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operators.
need this by tonight pls using python Write a program that asks the user to enter a month (1 for January, 2 for February, and so on) and then prints the number of days in the month. For February, print “28 or 29 days”. Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operator
Write a C++ program that determines the user's age after the user enters both the current date and hisher birthdate as 3 integers: yyyy mm dd Define a class which is named DateType and will be used to declare 2 objects: "birthday" and "today". The class will have a function "output" which will display the date in conventional form (like it is above next to Date Assigned: Month dd, yyyy and it will have a second function named “input”...
Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...
c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called MinilabLoopLogic which does the following Asks the user to enter 2 integers (can be one prompt or two) Gets and stores the ints Explains that the program will generate all integers that are between the numbers and are divisible by a third integer . e Asks the user for the number they should be divisible by Gets and stores that int Since 0 will...
Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...
All information about the question (Task 1 and task 2) are down below Programming Assignments Task 1 – Page 39. in Programming A Comprehensive Introduction Update your program from Assignment 2, Task #2 Allow the user to input their weight for the earth weight to moon weight conversion problem. Add an ifstatement that prompts the user if she inputs 0 or a negative number for her earth weight. #13. Mars’ gravity is about 17 percent less that of the earth’s....
Write a C program that asks the user to enter two real numbers. Then your program displays a menu that asks the user to choose what arithmetic operation to be done on those numbers. Depending on the user's entry, the program should display the result to the screen. The sample runs below show what should be done to the numbers entered by the user. Your program should run exactly like shown in the sample runs. make your code run as...
// Group Names: // Date: // Program Description: // Import required packages //--> // Declare class (SwitchDoLab) //--> { // Declare the main method //--> { // Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3. //--> //--> //--> // Create an integer variable named choice to store user's option. //--> // Create a Scanner object // Create...
Write codes that will produce the screen as shown Firstly, the program prompts user to enter his name. Then it will display Hello <user name>. Next it prints out a menu which contains 5 options (1- add two integers, 2- add two strings, 3- compute factorial, 4- reverse a string, 5- quit program). Code all 5 tasks appropriately. When the task is completed (not including quitting program of course), the menu pops up again and asks user to try...