Re: Java code Question



Note that you shouldn't have System.exit(1) in there. It isn't needed as the main method is about to terminate anyway, and the value 1 is used to indicate an unexpected termination. If you feel you have to have it, use System.exit(0) instead.

You'll have to convert your char digit to an int to use as the limit of an inner loop. Something like:
int reps = Integer.parseInt(Character.toString(digit));
but there has to be a better way - help me Roedy!


BTW, it's nice to have a name - who are you?

Mark

JavaClueless via JavaKB.com wrote:
I have to do this assignment:

Write a program that reads a social security number written as contiguous
digits (for instance, 509435456), uses the charAt method to obtain each
character and then prints each digit on a separate line followed by a colon
and the digit printed the number of times equal to its value. Thus the output
for 509435456 would be

 5:55555
 0:
 9:999999999
 4:4444
 3:333
 5:55555
 4:4444
 5:55555
 6:666666

So far I have gotten this far:



import javax.swing.JOptionPane;

public class Prog3
//Assignment # 3
{
public static void main(String[] asd)
{ String s = JOptionPane.showInputDialog("Type Your Social Security Number
Here:");
int len = s.length();
char digit;
for(int j =0; j < len; j++)
{
digit = s.charAt(j);
System.out.println(digit);
}
System.out.println();//seoparates ouutput from "To continue.." message
System.exit(1);
}
}


and I get the numbers going down.
What do i do next?

.



Relevant Pages

  • Maximum run of one digit in decimal expansion of pi?
    ... I'm a math layman with a question about pi. ... of one digit within the decimal expansion of pi? ... there is an infinite number of 0s in that decimal expansion. ... can a decimal terminate in any ...
    (sci.math)
  • Re: An uncountable countable set
    ... Tony Orlow schrieb: ... that does *not* terminate. ... can be shown to lie between two existing numbers, ... each digit is greater than the corresponding digit in the first, ...
    (sci.math)
  • Re: An uncountable countable set
    ... that does *not* terminate. ... It's still some kind of quantitative expression, ... I think it can be shown to lie between ...111 and ...555, given that each digit is greater than the corresponding digit in the first, and less than the corresponding digit in the second. ...
    (sci.math)
  • Re: Proper use of scanf
    ... have published some routines which operate directly on the input ... Barring EOF it will NOT be a digit. ... This forbids overflow, ... int readxwd ...
    (comp.lang.c)
  • Re: A portability poser: adding two unsigned shorts
    ... The problem occurs if the width of int is exactly 1 larger than the ... instead I have a type 'digit', which is a typedef for some unsigned ... except that this still has the same portability problem as above. ... digit) for any unsigned integer type 'digit'. ...
    (comp.lang.c)