d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Number Incrementer Real Work Applications! > Please Help =[
Add Reply New Topic New Poll
Member
Posts: 9,718
Joined: Jan 29 2007
Gold: 0.00
Oct 14 2014 05:41pm
I dropped out of my Comp Sci program cause I disliked coding I've finally found a use case that would benefit me in real life :D and wish I knew how now.

This might not be do-able in Java I dunno about VB or basic as its a large number. Also from my pseudo code below I suppose you might get that I make bash or powershell scripts still from time to time =\


I recently sent something to the states from Canada via Canadapost/USPS. I'm being bugged about tracking and when I went to use the tracking number I provided(a week later mind you) it appears I've included a typo. I no longer have the receipt and google didn't have anything for me.

Anyways heres my programming problem.

I have my typo number here: 277986102468

Can someone make me a program that takes the original number and increments each position x from 1-9 then outputs it comma seperated?

I guess it would be something along hte lines of
x= 277986102468

then(i don't know how to formulate this part)
for(loop) {
y=i77986102468 /* this loop moves i farther into the number, replacing the previous position with its original integer value, next iteration would be 2i7986102468
for (i=1; i<10; i ++) {
output += "i77986102468" + "," /* replaces i with the iteration of loop then stores it in variable output with a comma seperation. 177986102468,277986102468,377986102468 so on
}

}

$output /* prints text for copying. USPS lets me input 35 comma seperated values at a time.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 14 2014 05:56pm
not sure what you're asking. if you want to increment every digit from 1 to 9, i assume you want to get every permutation? you'll need a lot more than 35 at a time.
Member
Posts: 6,562
Joined: Oct 29 2007
Gold: 4.00
Oct 14 2014 06:24pm
this is broken but I think he wants something like this

Code
String num = "277986102468";
char[] numc = num.toCharArray();
char[] hold = num.toCharArray();

for (int i = 0; i < 12; i++) {
for (int j = 0; j < 10; j++){
numc[i] = ((char)j);
System.out.println(String.valueOf(numc));
}
numc[i] = hold[i];
}
Member
Posts: 16,411
Joined: Apr 9 2007
Gold: 12,059.17
Oct 14 2014 06:41pm
about the outer loop: as you said you want to move through all characters, so that should start something like:

Code
String typo = "277986102468";
for (int i = 0; i < typo.length; i++) {
for (int j = 0; j < 10; j++) {
StringBuilder candidate = new StringBuilder(typo);
candidate.setCharAt(i, j);
}
}


This post was edited by Ironfister on Oct 14 2014 06:42pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll