Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am doing my assignment t so i don't want post the whole code. I have problem with my code, i am using switch to

I am doing my assignment t so i don't want post the whole code. I have problem with my code, i am using switch to give the user option after the user choices it will ask to guess and i want the input to be string, but for some reason its not working. Why i cant use string when i am using switch statement. Instead of getting the input it jumps to else statement. please help me out. I will post the code and the output, i want know what i am doing wrong and i will appreciate if you explain it to me as why its done that way. Thanks.

image text in transcribed

Thats the code and i posted the output it giving me down below, please remember the number 2 is the case 2 and i am using switch

image text in transcribed

It wouldn't give me the option to write it down af, er i choose 2 which is the case 2 it will jump to else statement instead of the option to give to write even or odd.

MUUMIT TIITT YCUCIUC CWU TUUM TUM int number2=(int) (Math.random() *(6-1+1)+1); int total =number1+number2; 1 System.out.println("Please guess the number wether its odd or even.".+ total.);1 String diceroll=input.nextLine(); if (total:%2==0 && diceroll.equals("even")) { System.out.println("Victory! You guessed correctly! The answer is."+ diceroll);}1 .... else if (total % 2==1 && diceroll.equals("odd")) {1 T System.out.println("Victory! You guessed correctly, The answer is.".+ diceroll); 1 }1 else { System.out.println("your answer is incorrect");} 1 2 Please guess the number wether its odd or even 6 your answer is incorrect

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago