Question

java How do you take a method and using case switch make it so that when...

java

How do you take a method and using case switch make it so that when you enter 4 it brings up a certain method

0 0
Add a comment Improve this question Transcribed image text
Answer #1


import java.util.Scanner;

public class TestMethod {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter number: ");
       int n = sc.nextInt();
       switch (n) {
       case 4:
           fun();
       }
   }

   private static void fun() {
       System.out.println("I am fun");
   }

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
java How do you take a method and using case switch make it so that when...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java method that accepts (so you don't need to make an array for it) a 2d...

    Java method that accepts (so you don't need to make an array for it) a 2d array.of unknown row and column length. it functions like minesweeper but a lot smaller scale. basically in this case the 0's in the array indicate nothing an 8's indicate a mine. So squares surrounding the 8 (mine) indicate how many mines are adjacent to it. So if there are two mines adjacent to one squre it will show two.so like this. 0 1 1...

  • Pick a switch statement from the reading. Put it into a main() Java program and make...

    Pick a switch statement from the reading. Put it into a main() Java program and make it work. Attach the .java file and copyAndPaste the output into the WriteSubmissionBox The switch Statement S1.51 Multiway if-else statements can become unwieldy when you must choose from among many possible courses of action. If the choice is based on the value of an integer or character expres- sion, the switch statement can make your code easier to read. The switch statement begins with...

  • How do you implement a stack using a singly linked list in Java? Can you make...

    How do you implement a stack using a singly linked list in Java? Can you make it a simple implementation with just push and pop methods.

  • Please make a JAVA program for the following using switch structures Write a program that simulates...

    Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...

  • How would you write the following program using switch statements instead of if-else statements (in java)...

    How would you write the following program using switch statements instead of if-else statements (in java) import java.util.*; public class ATM { public static void main(String[] args) { Scanner input = new Scanner (System.in); double deposit, withdrawal; double balance = 6985.00; //The initial balance int transaction; System.out.println ("Welcome! Enter the number of your transaction."); System.out.println ("Withdraw cash: 1"); System.out.println ("Make a Deposit: 2"); System.out.println ("Check your balance: 3"); System.out.println ("Exit: 4"); System.out.println ("***************"); System.out.print ("Enter Your Transaction Number "); transaction...

  • java Write a method takeAWalk which will take an argument saying how many spare minutes you...

    java Write a method takeAWalk which will take an argument saying how many spare minutes you have for your walk (a whole number), and will print out where you will go using System.out.println. If you have at least 60 minutes for your walk, you will go to the store: print "Store". Otherwise, if you have at least 10 minutes, you will walk around the block: print "Block". Otherwise, print "Nowhere". The method does not return any value.

  • How do I type 2.18 into java? We have to make up a scenario and put...

    How do I type 2.18 into java? We have to make up a scenario and put it into netbeans java. range increases byte, short, int, long, float, double Lab2: Calculate Changes Problem Statement: This program lets the user enter the amount in decimal representing dollars and cents and output a report listing the monetary equivalent in single dollars, quarters, dimes, nickels, and pennies. Your program should report maximum number of dollars, then the maximum number of quarters, and so on,...

  • WRITE a program in JAVA using GRAPHICAL USER INTERFACE to make fruit and vegetable display panel with a toggle switch.(m...

    WRITE a program in JAVA using GRAPHICAL USER INTERFACE to make fruit and vegetable display panel with a toggle switch.(make two displays panel 1 for fruit and the other for vegetables , if we press the toggle switch then the 1st panel will show and if we again press the switch then the 1st will hide and other will show) and vice versa.

  • How would I code this method in Java using a scanner? Begin by asking how many...

    How would I code this method in Java using a scanner? Begin by asking how many spaces the row should be with a prompt using System.out.print like the following, with 40 as the maximally allowed number of spaces: (user input shown bold) Please enter the number of spaces for the game (1-40): eight To do this, use the promptNumberReadLine method that you will write, described on the back page. If the user does not type a number in the correct...

  • Java Switch Case Make From Pseudocode

    The following pseudo-code describes a menu-driven algorithm:loopask the user to input one of the characters a, b, c, d, e, q read in a character from the keyboardif the character is'a' output your name and your tutor's name (hard-coded) 'b' input 3 double numbers x, y, z and output the largestand the smallest of the three numbers'c' input 2 integer numbers m and n, and display all thenumbers between m and n (both inclusive) with five numbers per line (note...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT