Question

In: Computer Science

please make a program by DrRacker Suppose that we wish to add a new kind of...

please make a program by DrRacker

Suppose that we wish to add a new kind of expression known as a case of expression, which acts like a kind of switch-case or if-else-if conditional with multiple outcomes. An example of a case-of expression is: case f x of 0 -> 1; 1 -> 3; 2 -> 5; 3 -> 7; --> 0 The value of the above expression is 0 when the function's return value is none of 0, 1, 2, or 3.

Solutions

Expert Solution


import java.util.*;
public class Main
{
        public static void main(String[] args) {
            
            Scanner sc= new Scanner(System.in);
            int x= sc.nextInt();
            
            switch(x)
            {
               case 0: System.out.println("1");
                        break;
               case 1: System.out.println("3");
                        break;
               case 2: System.out.println("5");
                        break;
               case 3: System.out.println("5");
                        break;
               default: System.out.println("0");
                        break;
            }
        }
}


Related Solutions

Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
1. We wish to make a planoconcave lens out of polycarbonate that will make a virtual...
1. We wish to make a planoconcave lens out of polycarbonate that will make a virtual image reduced in size by a factor of exactly 4 when an object is placed 12.0 cm in front of it. a) What is the magnification? b) What is the focal length of the lens? c) Find the radius of curvature of the concave surface of the lens. d) Will the image be upright or inverted? e) Where will the image appear? f) Draw...
suppose a regression model has two explanatory variables (x and z). If we add a new...
suppose a regression model has two explanatory variables (x and z). If we add a new variable to to the model (m), and this new variable is correlated to x and z, how would we use the new variable m to test the impact of variable x on our dependent variable y when z and m remain the same?
Suppose we are given a set ? containing 2? integers, and we wish to partition it...
Suppose we are given a set ? containing 2? integers, and we wish to partition it into two sets ?1 and ?2 so that |?1 | = |?2 | = ? and so that the sum of the numbers in ?1 is as close as possible to the sum of those in ?2. Let the neighborhood ? be determined by all possible interchanges of two integers between ?1 and ?2. Is ? exact?
Suppose we make a face recognition program. In this case, set about 6 to 10 important...
Suppose we make a face recognition program. In this case, set about 6 to 10 important functions and draw a graph of their relationship. Tell me briefly about the role of each function. Thank you!
The first program is to count the number of zeros in $3855. Please     add comments...
The first program is to count the number of zeros in $3855. Please     add comments to each line                 org   $1000 array     db $38, $55 ; data to be tested                      org $1100 zero_cnt ds.b   1 lp_cnt     ds.b   1              org   $1500              clr   zero_cnt       ;initialize the 0 count to 0              movb #16,lp_cnt                   ldd   array         again     lsrd             bcs   chk_end         ;             inc   zero_cnt chk_end   dec   lp_cnt                           bne   again                               swi                          end
Suppose that we wish to test a claim that a sequence of sample data was produced...
Suppose that we wish to test a claim that a sequence of sample data was produced in a random manner, and suppose that each data value belongs to one of two categories. Let n1n1 be the number of elements in the sequence that belong to the first category, n2n2 be the number of elements in the sequence that belong to the second category, and GG be the number of runs in such a sequence. Answer each of the following questions...
Suppose that we wish to test a claim that a sequence of sample data was produced...
Suppose that we wish to test a claim that a sequence of sample data was produced in a random manner, and suppose that each data value belongs to one of two categories. Let n1 be the number of elements in the sequence that belong to the first category, n2 be the number of elements in the sequence that belong to the second category, and G be the number of runs in such a sequence. Answer each of the following questions...
Suppose that we wish to test a claim that a sequence of sample data was produced...
Suppose that we wish to test a claim that a sequence of sample data was produced in a random manner, and suppose that each data value belongs to one of two categories. Let n1n1 be the number of elements in the sequence that belong to the first category, n2n2 be the number of elements in the sequence that belong to the second category, and GG be the number of runs in such a sequence. Answer each of the following questions...
In C++ please modify the following program and add characters (char) and names (strings) to be...
In C++ please modify the following program and add characters (char) and names (strings) to be added to the linked list along with integers. The current demo program accepts only integer data, so you would ask the user to select the data type to be added to the linked list. The user should be given the following three choices: (a) whole numbers (b) single characters (c) strings Once the user makes a selection from the list above then your program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT