Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:22:50+00:00 2026-06-02T10:22:50+00:00

I am trying to generate a digit to execute switch statement but it is

  • 0

I am trying to generate a digit to execute switch statement but it is not generating proper result. But when the IF block is removed it works properly. What is the problem in the code?

import static java.lang.Character.isDigit;
public class TrySwitch
{
  enum WashChoise {Cotton, Wool, Linen, Synthetic }
  public static void main(String[]args)
        {

        WashChoise Wash = WashChoise.Cotton;
        int Clothes = 1;
         Clothes = (int) (128.0 * Math.random());
         if(isDigit(Clothes))
         {
            switch (Clothes)
            {
                case 1:
                System.out.println("Washing Shirt");
                Wash = WashChoise.Cotton;
                break;
                case 2:
                System.out.println("Washing Sweaters");
                Wash = WashChoise.Wool;
                break;
                case 3:
                System.out.println("Socks ");
                Wash = WashChoise.Linen;
                break;
                case 4:
                System.out.println("washing Paints");
                Wash = WashChoise.Synthetic;
                break;

            }
                switch(Wash)
                {
                    case Wool:
                    System.out.println("Temprature is 120' C "+Clothes);
                    break;
                    case Cotton:
                    System.out.println("Temprature is 170' C "+Clothes);
                    break;
                    case Synthetic:
                    System.out.println("Temprature is 130' C "+Clothes);
                    break;
                    case Linen:
                    System.out.println("Temprature is 180' C "+Clothes);
                    break;

                 }              
                }   
         else{
             System.out.println("Upps! we don't have a digit, we have  :"+Clothes );
                  }
        }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:22:52+00:00Added an answer on June 2, 2026 at 10:22 am

    The trick is that the isDigit method is meant for characters and detecting whether they represent a number. For example isDigit(8) == false because 8 maps to backspace in ASCII, but isDigit('8') == true since ‘8’ is really 56 in ASCII.

    What you might want to do is remove the if altogether and change your random generation to always produce a number between 1 and 4. This can be done as follows:

    Clothes = ((int) (128.0 * Math.random())) % 4 + 1;
    

    The % 4 will make sure the value is always between 0 and 3, and the + 1 shifts the range to 1 to 4.

    You can also use the Random class included with java:

    import java.util.Random;
    ...
    Clothes = new Random().nextInt(4) + 1
    

    Once again the + 1 shifts the range to be 1 to 4 inclusive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use php to generate a 9 digit number that does not
Im trying to generate a color gradient using ColdFusion. My current code below works
What I am trying to do is to generate some random numbers (not necessarily
i am trying to generate random number for my mental math quiz game. But
I am trying to generate all possible keypad sequences (7 digit length only right
Trying to generate Rails API documentation, but running into errors: $ rake doc:rails rake
I am trying to generate a random three digit extension: >>> ''.join(str(x) for x
Im trying to generate RSS page with CListView but i got additional generated html
Trying to generate XML file from returend SQL query results. The SQL query returns
I trying to generate an input (type=button) and setting the onclick-Event to a function,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.