Sponsored Links


Results 1 to 2 of 2

Thread: need guidness in java code

  1. #1
    Senior Member saneha's Avatar
    Join Date
    Apr 2011
    Posts
    266

    Thumbs up need guidness in java code

    Sponsored Links1


    sir

    my question about if user enter wrong input like enter text instead of number then out catch block will be executes and message appear what we type but sir i want to know how can i again get input or show the message again until user enter correct entry, like

    String total=JOptionPane.showInputDialog("Enter total number");

    try{

    float i=Float.ParseFloat(total);//if exception catch block executes

    }

    catch(NumberFormatException nfe{

    JOptionPane.showMessageDialoge("enter correct format");

    Sponsored Links

    }

  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    Following code explains how you can take input from user again and again. You can modify logic according to your need.





    import javax.swing.JOptionPane;



    public class AgainInput {



    public static void main(String[] args){



    float input = -1 ;

    while(input == -1){

    input = takeInput();

    }

    }





    public static float takeInput(){



    float i;

    String total=JOptionPane.showInputDialog("Enter total number");



    try{



    i=Float.parseFloat(total);//if exception catch block executes

    return i;

    }

    catch(NumberFormatException nfe){

    JOptionPane.showMessageDialog(null,"enter correct format");

    return -1;

    }



    }

    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. need guidness in java 2011
    By saneha in forum Java forum
    Replies: 1
    Last Post: 04-26-2011, 11:18 PM
  2. need java source code
    By moon13 in forum Java forum
    Replies: 3
    Last Post: 04-25-2011, 01:22 PM
  3. error code in java
    By saneha in forum Java forum
    Replies: 1
    Last Post: 04-24-2011, 10:04 PM
  4. little error in java code
    By saneha in forum Java forum
    Replies: 1
    Last Post: 04-24-2011, 09:44 PM
  5. native code in java
    By saneha in forum Java forum
    Replies: 1
    Last Post: 04-24-2011, 05:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft | Jobs