|
-
using the displayDigits() method to return integer value with spaces
The program takes the user's input which is an integer (no chars) that is > 1 and <= 99999 and calls the displayDigits() method to tear apart using division and modulus in for loop. For example, after the user enters an integer: 3456, the method should return the input value with two spaces between each digit.
// as global variables
int digit;
String output="";
String input;
public void actionPerformed( ActionEvent actionEvent ) {
input = inputField.getText();
displayDigits( input );
} // end method actionPerformed
public int displayDigits( input ) {
for( int numdigits=input.length; numdigits>=0; numdigits--) {
digit = Integer.parseInt( input )/math.pow( 10, numdigits-1 );
String digit = toString( digit );
digit = Integer.parseInt( input )%math.pow( 10, numdigits-1);
output += ""+digit+"";
} // end for loop
outputField.setText( output ); // writes output string to textbox
} // end method displayDigits
} // end class
-------------------------------------
There are 4 errors related to the displayDigits() method including the parameter. I'm not sure whats wrong... The brackets are fine. Maybe it has to do with how this method ends.. Can anyone help me out here.. I would be appreciated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks