[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 =)
does it work?
Moderator: Smeagol
- nobile
- Kakaist
- Posts: 522
- Joined: Wed Dec 12, 2001 00:32
- MySpace: www.myspace.com/nobile01
- Location: Honduras
- Contact:
does it work?
Beauty is in the eyes of the beholder <3
Who is online
Users browsing this forum: No registered users and 75 guests