04-24-2011, 09:41 PM
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;
}
}
}
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;
}
}
}
0300-9520262
Get solution in 24 hour |cpmputer & internet
mileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
