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?
Make a java program of Mickey I have the starter program but I need to add...
Make a java program of Mickey I have the starter program but I need to add eyes and a smile to it. import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JFrame; public class Mickey extends Canvas { public static void main(String[] args) { JFrame frame = new JFrame("Mickey Mouse"); Canvas canvas = new Mickey(); canvas.setSize(400, 400); canvas.setBackground(Color.white); frame.add(canvas); frame.pack(); frame.setVisible(true); } public void paint(Graphics g) { Rectangle bb = new Rectangle(100, 100, 200, 200); mickey(g, bb); } public void...
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!
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...
This is a combinatorics problem Suppose we wish to find the number of integer solutions to...
This is a combinatorics problem Suppose we wish to find the number of integer solutions to the equation below, where 3 ≤ x1 ≤ 9, 0 ≤ x2 ≤ 8, and 7 ≤ x3 ≤ 17. x1 + x2 + x3 = r Write a generating function for this problem, and use it to solve this problem for r = 20.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT