Program needs to output the number and how many digits the number have. Example:
1000
4 Digits
Here is the code:
Method class:
import javax.swing.JOptionPane;
public class digit
{
String output="";
public int count_digits(int x)
{
output+=x+"\n";
if (x<10)
return 1;
else
return 1+count_digits(x/10);
}
public void Result()
{
JOptionPane.showMessageDialog(null,output,"output",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
Main class:
public class digmain
{
public static void main(String args[])
{
digit x=new digit();
x.count_digits(9999);
x.Result();
}
}

New Topic/Question
Reply




MultiQuote






|