The Artima Developer Community
Sponsored Link

Java Answers Forum
How do i loop

2 replies on 1 page. Most recent reply: Nov 16, 2002 1:26 AM by Ernie Douglas

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Ernie Douglas

Posts: 18
Nickname: y2j
Registered: Nov, 2002

How do i loop Posted: Nov 15, 2002 3:07 PM
Reply to this message Reply
Advertisement
could someone show me how do i put a loop in this coding please?

import javax.swing.JOptionPane;

public class Comparison {
public static void main ( String args [] )
{

String firstNumber; // first string entered by user

//declaring a variable
int number1 ;

Integer x; // java has a class named Integer at java.lang
x = new Integer(5);

firstNumber = JOptionPane.showInputDialog ( "Enter Five digit integer:" );

//Entering the numbers
number1 = Integer.parseInt ( firstNumber );

if ( number1 > 99999 ) // Defining No more than 5 DIGITS
// Warning message of Too much
JOptionPane.showMessageDialog(
null, "Too many digits", "Program by",
JOptionPane.WARNING_MESSAGE );
else
if ( number1 <= 9999 ) // Defining No less than 5 DIGITS

// Warning message of Insufficiant digits
JOptionPane.showMessageDialog(
null, "Insufficiant digits", "Program by",
JOptionPane.WARNING_MESSAGE );

else
{
x=new Integer (number1);

JOptionPane.showMessageDialog (null, x.toString ().charAt (0) + "---" +
x.toString ().charAt (1) + "---" + x.toString().charAt (2)
+ "---" + x.toString().charAt (3) + "---" + x.toString().charAt (4) + " ", "Program By",
JOptionPane.INFORMATION_MESSAGE );

}

System.exit ( 0 );

}}


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: How do i loop Posted: Nov 15, 2002 8:21 PM
Reply to this message Reply

import javax.swing.JOptionPane;

public class Comparison {

public static void main ( String args [] ){
boolean done = false;
while (!done){
Integer x = new Integer(5);
/* first string entered by user */
String firstNumber = JOptionPane.showInputDialog ( "Enter Five digit integer:" );
int number1 = -1;
/* Entering the numbers */
try{
/* Check to make sure it is an integer. */
number1 = Integer.parseInt (firstNumber);
}catch(NumberFormatException nfe){
number1 = -1;
System.err.println("NumberFormatException: " + nfe.getMessage());
}
if (number1 > 99999 ) {
/* Defining No more than 5 DIGITS */
/* Warning message of many digits. */
JOptionPane.showMessageDialog(
null, "Too many digits", "Program by",
JOptionPane.WARNING_MESSAGE );
}else if ((number1 <= 9999 )&& (number1 > 0)){
/* Defining No less than 5 DIGITS */
/* Warning message of Insufficient digits */
JOptionPane.showMessageDialog(null, "Insufficient digits", "Program by",
JOptionPane.WARNING_MESSAGE );
}else if (number1 < 0){
/* Warning message of Incorrect Entry */
JOptionPane.showMessageDialog(null, firstNumber + " was not a 5 digit integer", "Error",
JOptionPane.ERROR_MESSAGE );
}else{
x = new Integer (number1);
JOptionPane.showMessageDialog (null, x.toString ().charAt (0) + "---" +
x.toString ().charAt (1) + "---" + x.toString().charAt (2)
+ "---" + x.toString().charAt (3) + "---" + x.toString().charAt (4)
+ " ", "Program By", JOptionPane.INFORMATION_MESSAGE );
}
int result = JOptionPane.showConfirmDialog (null, "Do you want to Continue");
done = ((result == JOptionPane.NO_OPTION) || (result == JOptionPane.CANCEL_OPTION));
}
System.exit (0);
}
}

Ernie Douglas

Posts: 18
Nickname: y2j
Registered: Nov, 2002

Re: How do i loop Posted: Nov 16, 2002 1:26 AM
Reply to this message Reply
OH you the man charles, thanks a lot mate

Flat View: This topic has 2 replies on 1 page
Topic: String vs StringBuffer Previous Topic   Next Topic Topic: Help please

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use