Re: Java code Question
- From: Mark Thomas <anon>
- Date: Thu, 15 Dec 2005 10:58:54 +0000
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?
.
- Follow-Ups:
- Re: Java code Question
- From: Mark Thomas
- Re: Java code Question
- From: Roedy Green
- Re: Java code Question
- References:
- Java code Question
- From: JavaClueless via JavaKB.com
- Java code Question
- Prev by Date: Re: I have a crisis
- Next by Date: Re: Java code Question
- Previous by thread: Re: Java code Question
- Next by thread: Re: Java code Question
- Index(es):
Relevant Pages
|