need guidness in java code
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1 • Share
need guidness in java code
sir plzz help mee!
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");
}
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");
}
sharmila farooqi- Monstars
- Posts : 35
Join date : 2011-05-29
Re: need guidness in java code
Following code explains how you can take input from user again and again. You can modify logic according to your need.
- Code:
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;
}
}
}
Vuhelper- Deep Bench
- Posts : 97
Join date : 2011-05-29
Similar topics
» Native code in java
» little error in java code
» how can we run the java code ? after saving the file how run it?
» java documentation
» What is difference b/w java Buzzwords and java Keywords?
» little error in java code
» how can we run the java code ? after saving the file how run it?
» java documentation
» What is difference b/w java Buzzwords and java Keywords?
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Yesterday at 12:21 pm by ali001
» Hemangiom'App
Tue Nov 05, 2024 11:25 am by ali001
» MindfulMe - Mental Health App
Mon Nov 04, 2024 10:50 am by ali001
» Learn Candlestick Patterns
Tue Oct 15, 2024 5:51 am by ali001
» Woh Pagal Si Episode 52 to 62 - Top Pakistani Drama
Sat Sep 21, 2024 6:26 pm by Mir Emmad Ali Khan Domki
» Nearu - share your socials
Sat Sep 21, 2024 1:12 pm by ali001
» Nightclub Tycoon: Idle Empire
Thu Sep 19, 2024 9:16 pm by ali001
» Carnivore - Meat Diet Recipes
Wed Sep 18, 2024 2:37 pm by ali001
» Eid Milad un Nabi Mubarak 2024 (Rabiʻ I 14, 1446 AH)
Tue Sep 17, 2024 3:44 pm by Mir Emmad Ali Khan Domki