How Do I Cotrol the Flow of Execution of this Code ?

HI,
I am trying to write a code that can take all the user information at the command prompt and displays the same entered information. My code works well upto taking theh data and displaying..
But, now i want to put some restrictions like entering valid acceptable data for ex.: for gender only male or female and not anything else.
So I implemented this using the string comparison ignoring the cases just for the gender, using the "==" operator and the if statement.
Now my desire was to check the input data at gender and see if it valid like male/female or not irrespective of cases, and then asking the user to renter that right value for gender. and should not proceed until entered properly. But my code checks it and skips to the next data to be fed !
How do I control that flow of my code ie., it should not go ahead after checking the validity of data entered until the right data is fed ??
MY CODE IS:
import java.io.*;
import java.lang.*;
class Profilev1{
public static void main(String args[]) throws IOException{
String gend=null;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter your name:\r");
String name=br.readLine();
b1:{System.out.println("Please enter your gender Male/Female :\r");
gend=br.readLine();
if(gend!="male" && gend!="female")
     {     System.out.println("Please enter either Male or Female\n");
break b1;
System.out.println("Please enter your age:\r");
int age= Integer.parseInt(br.readLine());
System.out.println("Please enter your salary $Dollars.cents:\r");
float sal=Float.parseFloat(br.readLine());
System.out.println("\n\nThank You "+name+".\n\n\nHere's your profile with us on file :\r");
System.out.println("Name:\t"+name+"\nGender:\t"+gend+"\nAge:\t"+age+"\nSalary:\t"+sal+"\r");
OUTPUT IS:
C:\Program Files\Java\jdk1.6.0_02\bin>javac Profilev1.java
C:\Program Files\Java\jdk1.6.0_02\bin>java Profilev1
Please enter your name:
Aron Philip
Please enter your gender Male/Female :
male
Please enter either Male or Female
Please enter your age:
100
Please enter your salary $Dollars.cents:
75600.23
Thank You Aron Philip.
Here's your profile with us on file :
Name: Aron Philip
Gender: male
Age: 100
Salary: 75600.23
C:\Program Files\Java\jdk1.6.0_02\bin>
Message was edited by:
aron_phil

Actually, I often use the equalsIgnoreCase instead of teh equals method, but you use them the same way.
Here are two examples:
import java.util.Scanner;
class Fubar 
    private Scanner sc = new Scanner(System.in);
    private void testKeepGoing()
        boolean keepGoing = true;
        while (keepGoing)
            System.out.print("Enter \"goodbye\" to quit: ");
            String goodbyeString = sc.nextLine();
            if (goodbyeString.equalsIgnoreCase("goodbye"))
                keepGoing = false;
    private void testTypeQuit()
        Scanner sc = new Scanner(System.in);
        String quitString = "";
        while (!quitString.equalsIgnoreCase("quit"))
            System.out.print("Type \"quit\" to exit: ");
            quitString = sc.nextLine();
        sc.close();
    public static void main(String[] args)
        Fubar foo = new Fubar();
        foo.testKeepGoing();
        foo.testTypeQuit();
}

Similar Messages

  • How do I cancel the flow of emails from support communities?

    How do I cancel the flow of emails from support communities?

    See this User tip...
    https://discussions.apple.com/docs/DOC-3661

  • I am having a Startup problem. Someone comes on the screen with Open Firmware to Startup. How can I reset the PRAM myself to solve this problem?

    I am having a Startup problem. Someone comes on the screen with Open Firmware to Startup. How can I reset the PRAM myself to solve this problem?

    Read these.
    http://support.apple.com/kb/HT1431
    http://reviews.cnet.com/8301-13727_7-10330118-263.html

  • Using windows 8.1 and photoshop cs4 the font size of the MENUS is so small as to be almost unreadable.  how do i make the menu fonts larger.  this is happening also with bridge

    Using windows 8.1 and photoshop cs4 the font size of the MENUS is so small as to be almost unreadable.  how do i make the menu fonts larger.  this is happening also with bridge

    Thank you so much.  You are absolutely right.  I will have to reduce the screen density when I work with those programs.
    Thanks for your trouble and regards
    Quentin Sussman
    <mailto:[email protected]> [email protected]
    Cell: 082 4900 124
    Home:  011 883 2582
    Fax: 086 680 7981

  • After making a call I put my phone in my pocket and when I bring it out to make a call the player is on killing battery life. How can I shut the player off or prevent this from happening?

    after making a call I put my phone in my pocket and when I bring it out to make a call the player is on killing battery life. How can I shut the player off or prevent this from happening?

    Try to position your iphone that the screen is facing away from your skin.
    Make sure that the back part of your phone will be the one that will contact your skin inside your pocket
    Thats what i do:)

  • I have a question about the new version of itunes. in the old version at the bottom of the sceen it display the total number of media and the size of the files. how can i get the new version to diplay this?

    in the old version at the bottom of the sceen it displayed the total number of media and the size of the files. how can i get the new version to diplay this?

    You're welcome. It was frustrating for me as well until I stumbled across "the fix"

  • How can i fix "the sim card inserted in this iphone does not appear to be supported " after restoring a factory unlocked iphone 4

    how can i fix "the sim card inserted in this iphone does not appear to be supported " after restoring a factory unlocked iphone 4

    The term "factory unlocked" has no meaning. Your phone was not legitimately unlocked. Contact the carrier it is locked to and find out if you can get it unlocked.

  • HT1657 I've downloaded a movie, but there is no play button. How do I play the movie? Never had this problem before.

    I've downloaded a movie, but there is no play button. How do I play the movie? Never had this problem before.

    I deleted the movie from my itunes library and went to my purchased items, but how do I download from my purchased items. It shows I purchased the movie but thats it.
    Thanks for the help!

  • I purchased ios 3.1.1 about 2 years ago when I got the ipod. I swapped out my old i touch at the genius bar at the apple store, so now i'm stuck with 1.1.5. How can I redeem the update i bought on this new swapped out?

    I PURCHASED IOS 3.1.1 ABOUT 2 OR 3 YEARS AGO WHEN I GOT THE IPOD, I SWAPPED MY OLD I TOUCH AT THE GENIUS BAR AT THE APPLE STORE, SO NOW IM STUCK WITH 1..1.5.  HOW CAN I REDEEM THE UPDATE I BOUGHT ON THIS NEW SWAPPED OUT?

    Contact iTunes
    Apple - Support - iTunes Store - Contact Us
    If you have the same computer on which you originally did theupdate, have you trued restoring the iPod?  The 3.1.1 update should stillbe on yur computer.  It is located here on a PC
    ipsw location

  • How could I find the SQL statement who get this message ?

    ORA-01555 caused by SQL statement below (Query Duration=11191 sec, SCN: 0x0854.723b9c32)
    ... How could I find the SQL statement who got this message ?
    Thanks, Paul

    ORA-01555 means that the UNDO/ROLLBACK space is not large enough.
    This occurs because the SELECT statement is attempting to read the UNDO, but the UNDO has been released (transactions have committed or rolled back) and reused.
    The following are SOME of the reasons I have seen this to occur:
    1) Updates in a loop, with commits happening in the same loop
    - this will mark the UNDO available quickly and quickly reuse it. Then when the SELECT wants to rebuild a block, the UNDO used to rebuild the block has been reused (solution, make the UNDO bigger)
    2) A SELECT cursor used to control a loop in which updates are performed, and a 'done' flag is marked against the current cursor record, and commits are performed at the end of each loop, prior to fetching the next record
    - same problem as above, but it hits the current process. Same solution
    3) A 'month end' activity spike occurs, and all sorts of transactions create updates. There is a report that reports the activity - amusingly it needs to start at the beginning of all the work and updates periodically by doing a huge SELECT up front. This is then used to drive a loop which attempts to get information from the various transactions that have been updated and committed. After a while, the SELECT gets an ORA-01555
    - same problem as above and same solution. Get a bigger UNDO segment.
    You say this only happens once a month. That should give a hint.
    I wouldn't bother with which SELECT statement, as much as which APPLICATIONs are being run when it happens.
    One way around this - use 10g and set the guaranteed retention period. All sorts of other things will break, by no more 1555. <g>

  • I have  a iphone 5 and i can not figure out how to turn on the LED notification light. is this even possable? if not how do i know if i missed a call when i was not there to answer it visualy

    I have  a iphone 5 and i can not figure out how to turn on the LED notification light. is this even possable? if not how do i know if i missed a call when i was not there to answer it visualy

    If you were not there, how would you see the led?
    Anyway missed calls will appear on your Lock screen under the Missed tab.
    Or a small red numbered badge will appear on the Phone App icon when you have missed calls. You can then access the Recents Tab in the Phone App to see whcih calls were missed.
    Missed Calls are shown in red there

  • How can I disable the assistive touch programmatically ? This is like a bug. Though the Guided access is enabled a user can take screenshot of my application content. How can I solve this ? any idea ....

    How can I disable the assistive touch programmatically ? This is like a bug. Though the Guided access is enabled a user can take screenshot of my application content. How can I solve this ? any idea ....

    Question: Do you think the response from the support staff is correct? I mean, surely, I can't be the only CF user on a shared box whose other users need to modify the date and time within their applications. Even if they do it at the application level for their domain, surely it wouldn't affect mine, would it? That was what was implied by the support people, but I have a feeling they are way off, or covering for some goof-up on their end. I struggled like hell yesterday trying to get this to work and I did not get very far at all.
    I found an interesting tutorial here which does a comparison of time zones and, theoretically, this might do the trick. But if what the guy told me was nonsense then I won't bother with it. For the record, our calendar has been working fine for about a week now.

  • TS1503 My iPhone 4 says that there is not enough memory to download apps like Facebook and Instagram. When plugged into iTunes it says that 4GB is filled with "other". How do I clear the "other"?  What is this?

    My iPhone 4 says that there is not enough memory to download apps like Facebook and Instagram. When plugged into iTunes it says that >4GB is filled with "other". How do I clear the "other"?  What is this?

    Other is usually around 1 GB...
    A  ' Large Other ' usually indicates Corrupt Data...
    First Try a Restore from Backup... But... if the Large Other Persists, that is an Indicator of Corrupt Data in the Backup... Then a Restore as New is the way to go...
    Details Here  >  http://support.apple.com/kb/HT1414
    More Info about ‘Other’ in this Discussion
    https://discussions.apple.com/message/19958116

  • How to use at last/ at end of in this code

    Hi,
    i want to do sum for each and every line item of the delivery quantity and compare it with final purchase order quantity if it is equal do not display in the output.(how to use at last/at end of ) in this code,
    below code wat i have ritten is only comparing first record with final purchase order quantity and displaying the output, but i want sum of every line item and compare with final quantity(purchase order quantity)
    if possible try modify this code
    clear:wa_final,wa_kopoo,wa_likpp1.
        loop at it_kopoo into wa_kopoo.
          move wa_kopoo-ebeln to wa_final-ebeln.
          move wa_kopoo-ebelp to wa_final-ebelp.
          move wa_kopoo-matnr to wa_final-matnr.
          move wa_kopoo-txz01 to wa_final-txz01.
          move wa_kopoo-menge to wa_final-menge.
          move wa_kopoo-meins to wa_final-meins.
          move wa_kopoo-werks to wa_final-werks.
          move wa_kopoo-matkl to wa_final-matkl.
          move wa_kopoo-reswk to wa_final-reswk.
          move wa_kopoo-aedat to wa_final-aedat.
          move wa_kopoo-ekgrp to wa_final-ekgrp.
          move wa_kopoo-EINDT to wa_final-EINDT.
        read table it_likpp1 into wa_likpp1 with key vgbel = wa_final-ebeln
                                                     vgpos = wa_final-ebelp.
          if sy-subrc eq 0.
            if wa_final-menge > wa_likpp1-LFIMG.
            else.
              continue.
            endif.
          endif.
          append wa_final to it_final.
          clear:wa_final,wa_kopoo,wa_likpp1.
        endloop.
      endif.

    Hi,
    Try this:
    define one more internal table it_final1 similar to i_final .
    CLEAR:wa_final,wa_kopoo,wa_likpp1.
    SORT it_kopoo BY ebeln ebelp.
    LOOP AT it_kopoo INTO wa_kopoo.
      move-corresponding wa_kopoo to wa_final.
      COLLECT wa_final INTO it_final1.
      CLEAR: wa_kopoo, wa_final.
    ENDLOOP.
    sort it_final1 by ebeln ebelp.
    LOOP AT it_final1 INTO wa_final.
      READ TABLE it_likpp1 INTO wa_likpp1 WITH KEY vgbel = wa_final-ebeln
                                                   vgpos = wa_final-ebelp.
      IF sy-subrc EQ 0.
        IF wa_final-menge NE wa_likpp1-lfimg.
          APPEND wa_final TO it_final.
        ENDIF.
      ENDIF.
    ENDLOOP.
    Regards,
    Subramanian

  • How do I remove the flower icon that automatically shows up in emails

    I would like to delete the flower icon that is attached to all of emails.  Can anyone please provide directions?

    Hi there! Are you talking about the search field on google.com? Or do you mean you are seeing words that you have previously have typed in? If it's the latter:
    #Click on the form field and press the down arrow key to display all the saved entries. You may type the first few letters of the entry to limit the number of entries displayed.
    #Use the down arrow key or the mouse pointer to highlight the entry you wish to delete.
    #Press Shift+Delete. The entry will be removed.
    Hope this helps!

Maybe you are looking for