Write an application called PracticeArithmeticOperators.java that inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the digits separated from one another by five spaces each. For example, if the user types in the number 49872, the program should print
4 9 8 7 2
The errors exist on all the lines with calculation, I continue to get :The operator % is undefined for the argument type(s) String, int : I have tried changing number to an integer but when I do this I get an error in my JOption Pane statement can someone please assist me with this.
Thank you
number/10000;
(number%10000)
(number%10000)
(number%10000)
(number%10000)
/***********************************************************************
Program Name: PracticeArithmeticOperators
Programmers Name: Audrey McCants
Program Description: This program will show a statement that displays each digit separated by Five spaces ***********************************************************************/
import javax.swing.JOptionPane;
public class PracticeArithmeticOperators {
public static void main(String[] args) {
String number; // number input by user
int dig1; // first digit
int dig2; // second digit
int dig3; // third digit
int dig4; // fourth digit
int dig5; // fifth digit
dig1 = number/10000;
dig2 = (number%10000)/1000;
dig3 = (number%10000)/1000/100;
dig4 = (number%10000)/1000/100/10;
dig5 = (number%10000)/1000/100/10/1;
System.out.print( "Enter five digit integer: " );
dig1 = 4;
dig2 = 9;
dig3 = 8;
dig4 = 7;
dig5 = 2;
number = JOptionPane.showInputDialog("Enter a number");
String result = "";
result = dig1 + " " + dig2 + " " + dig3 + " " + dig4 + " " + dig5;
System.exit(0);
}
}
This post has been edited by macosxnerd101: 30 October 2010 - 07:25 PM
Reason for edit:: Title renamed to be more descriptive.

New Topic/Question
Reply




MultiQuote



|