File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Modulus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Modulus" Watch "Modulus" New topic
Author

Modulus

Jeff Pickett
Greenhorn

Joined: Feb 04, 2001
Posts: 12
I'm don't understand how to seperate a group of numbers to their individual numbers using the mod operation. For example "5698721" into 5 6 9 8 7 2 1. This isn't a homework assignment. I'm teaching myself programming. Could someone please give me some direction?
Matts Smith
Ranch Hand

Joined: Feb 03, 2001
Posts: 113
Hey there,
bear with me if this code does not make sense, I just woke up.
<code>
long num = 5698721;
long mod = 10;
long modded = 0;
while ( num != 0 )
{
modded = num%mod;
System.out.println(modded / (mod/10));
num -= modded;
mod *= 10;
}
</code>
I leave you the pleasure of reversing the output.
also keep in mind it is not the best solution to separate digits in a number. you should use a String to do that
later.
sona gold
Ranch Hand

Joined: Feb 14, 2001
Posts: 234
try this
int num = 123 //declaration could be depending on the number
int a, b;
while (num!=0)
{
a = num % 10; // this will give u the last digit = 3
b = num / 10; //this will give u the number with the last digit removed = 12
num = b; // num which was 123 now is 12
}
and u could perform whatever operation u want to perform with "a"

sona<br />SCJP
sona gold
Ranch Hand

Joined: Feb 14, 2001
Posts: 234
i would appreciate if someone gives some suggestion on my solution
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Modulus
 
Similar Threads
Tree Question
� GBP Rate �
Head First Servlets & JSP Frustration
What irrational fears do you have?
Should parseInt() be able to parse like "+2"?