does it work?

Site backdrop/framework-related discussion & hosted site support

Moderator: Smeagol

User avatar
nobile
Kakaist
Kakaist
Posts: 522
Joined: Wed Dec 12, 2001 00:32
MySpace: www.myspace.com/nobile01
Location: Honduras
Contact:

does it work?

Postby nobile » Mon Mar 13, 2006 08:50

[syntax="java"]
import javax.swing.JOptionPane;
public class Modulo
{
public static int mod(int x)
{
int s=0,y;
for(int i=100;i>0;i/=10)
{
y=(x/i);
s+=y;
x-=(y*i);
}
return(s);
}
public static void main(String arg[])
{
String sn;
int in,suma=0;
sn=JOptionPane.showInputDialog("Give me a three digit number: ");
in=Integer.parseInt(sn);
while(in>1)
{
if(in>=100 && in<=999)
{
suma=mod(in);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Error, the number you gave me wasn't three digits.\nGive me a number again.","Error",JOptionPane.ERROR_MESSAGE);
}
sn=JOptionPane.showInputDialog("IGive me a three digit number: ");
in=Integer.parseInt(sn);
}
JOptionPane.showMessageDialog(null,"The sum of the digits is: "+suma,"Resultados",JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
[/syntax]
Just run it, please =)
Beauty is in the eyes of the beholder <3

Return to “Slowdev”

Who is online

Users browsing this forum: No registered users and 1 guest