Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Beginner // switch not recognizing upper case Q

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    8
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Beginner // switch not recognizing upper case Q

    Hi

    I was wondering if someone could be so kind as to help me figure out why this switch code does not work for the 'Q'.
    Everything works fine for the other cases, i.e. 1,2,3, and 'q', but when I type in 'Q', I get the default case. Please note all the values have been defined in an earlier part of the code but for simplicity's sake I have removed them below

        do {
     
     
            switch (choix) {
                //demande le nombre de patons a achete
                case '1': 
                    System.out.println (" Nombre de patons :");
                    nombreDePatons = Clavier.lireDouble();
                    while (nombreDePatons <= 0 ){
                        System.out.println (" Erreur : choix non valide1! ");  
                    }
                    patons = patons + nombreDePatons;
                    accumulateurPatons = accumulateurPatons + nombreDePatons;
                    break;
                    // demande le nombre de baguette à produire
                case '2':
                    System.out.println (" Nombre de baguette : ");
                    nombreDeBaguettes = Clavier.lireDouble();
                    while (nombreDeBaguettes <= 0 ){
                        System.out.println (" Erreur : choix non valide2! ");  
                    }
                    if (nombreDeBaguettes > nombreDePatons) {
                        System.out.println ("Pas de patons, pas de baguette! ");
                    } else if (nombreDeBaguettes <= nombreDePatons) {
                        baguette = baguette + nombreDeBaguettes;
                        patons = patons - nombreDeBaguettes;
                    }
                    break; 
                // demande le nombre de baguette à vendre
                case '3':
                    System.out.println (" Nombre de baguette : ");
                    baguetteAVendre = Clavier.lireDouble ();
                    while (baguetteAVendre <= 0 ){
                        System.out.println (" Erreur : choix non valide3! ");  
                    }
                    if (baguetteAVendre > nombreDeBaguettes) { 
                        System.out.println ("Pas de baguette, pas de ventes! ");
                    } else if (baguetteAVendre <= nombreDeBaguettes) {           
                        baguette = baguette - baguetteAVendre;
                        accumulateurBaguette = accumulateurBaguette + baguetteAVendre;
                    }
                    break;
                case 'q':   
                case 'Q':
                    break; 
                default:
                    System.out.println (" Erreur : choix non valide!");           
                    break; 
            }
        } while (choix != 'q' && choix != 'Q') ;
    }
    Last edited by Christian_Doucet; April 2nd, 2014 at 10:03 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Beginner // switch not recognizing upper case Q

    The code works for me. Try debugging it by printing out the value of choix just before the switch statement to see what the switch statement is using.
    Or have the default: case print out the value of choix that was used. A good idea in many cases to show what the invalid value was.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Christian_Doucet (April 2nd, 2014)

  4. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    8
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Beginner // switch not recognizing upper case Q

    Thanks for the help! It made me realize the switch was not recognizing both 'q' and 'Q', made me think about char issues and I realised that the input for "choix" was missing Ln at the end

    Problem solved

Similar Threads

  1. Upper and Lower Case in a sentence
    By torrie in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 25th, 2013, 04:51 AM
  2. how to search for upper/lower case using string using JAVA!!!?
    By eortiz10 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 25th, 2013, 06:56 AM
  3. how to ignore upper and lower case
    By mohamed_saleh2012 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2012, 03:49 PM
  4. wanting to convert printout to UPPER case
    By welikedogs in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 3rd, 2010, 01:22 PM
  5. [SOLVED] upper case
    By andaji in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 13th, 2010, 11:54 PM