Question: I have two problems I need to get finished that MUST BE IN JAVA. Problem 1: Convert this into using some sort of switch-case statement

I have two problems I need to get finished that MUST BE IN JAVA.

Problem 1:

Convert this into using some sort of switch-case statement this program should be name PrintNumberToWordie2 I need this program converted to some sort of switch case statement.

Our teacher gave us a kind of "hint" as to how he wants it done. I didn't understand it too much but I'll include it just incase it'll be some help.

Here's his hints:

/* * Trying nested-if and switch-case statements. */ public class PrintNumberInWord { // Save as "PrintNumberToWordie.java" public static void main(String[] args) { int number = 5; // Set the value of "number" here! // Using nested-if if (number == 1) { System.out.println( ...... ); } else if ( ...... ) { ...... } else if ( ...... ) { ...... ...... } else { ...... } // Using switch-case to do the same switch(number) { case 1: System.out.println( ...... ); break; // Don't forget "break" case 2: System.out.println( ...... ); break; ...... ...... default: System.out.println( ...... ); } } } // Demo sample for user input // Use as a guide import java.util.Scanner; class IfElse_Demo { public static void main(String[] args) { int marksObtained, passingMarks; passingMarks = 40; Scanner input = new Scanner(System.in); System.out.println("Input marks scored by you"); marksObtained = input.nextInt(); if (marksObtained >= passingMarks) { System.out.println("You passed the exam."); } else { System.out.println("Unfortunately, you failed to pass the exam."); } } }

Here's the code I have already written:

package printnumbertowordie;

import java.util.Scanner;

public class PrintNUmberToWordie {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter an integer: ");

int n = scan.nextInt();

if(n==1) {

System.out.println("ONE");

} else if(n==2) {

System.out.println("TWO");

} else if(n==3) {

System.out.println("THREE");

} else if(n==4) {

System.out.println("FOUR");

} else if(n==5) {

System.out.println("FIVE");

} else if(n==6) {

System.out.println("SIX");

} else if(n==7) {

System.out.println("SEVEN");

} else if(n==8) {

System.out.println("EIGHT");

} else if(n==9) {

System.out.println("NINE");

} else if(n==10) {

System.out.println("TEN");

} else {

System.out.println("No match found");

}

if(n % 2==0) {

System.out.println(n+" is divisible by 2.");

} else {

System.out.println(n+" is not divisible by 2.");

}

}

}

Output:

Enter an integer: 5 FIVE 5 is not divisible by 2.

Problem 2:

Write a user input program using if else statements ONLY name of program "Magic number" the user will try guess the Magic number. The user will enters the number to guess and computer will tell the user if the number matches the Magic number and then determine if the number is smaller or greater than the initial number. The Number that is guessed must be of type int and use Math.random() function to give it random value in range 1 thru 100.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!