code
package javahomework;
import javax.swing.JOptionPane;
public class HW04 {
public static void main(String args[])
{
int input;
input = Integer.parseInt(JOptionPane.showInputDialog(null,"Input Number"));
JOptionPane.showMessageDialog(null,"The sum of "+input+" is "+ADD(input));
}
static int ADD(int n)
{
if (n<10)
return n;
else
return (ADD(n/10)+ADD(n%10));
}
}
沒有留言:
張貼留言