int lotteryTemp = lottery; int lotteryOneDigit = lottery1 % 10; lotteryTemp = lotteryTemp / 10; ...
And so on with lottery2 and lottery3.
However, I'm having trouble with doing it with 9 digits. Here's the integer code I have, I'll post the whole program at the bottom. I'm able to successfully compile and run but I only get 2 digits for an output. =/ Not the 10 I'm hoping for.
int temp = isbn; int d9 = temp % 10; temp = temp / 10; int d8 = temp % 10; temp = temp / 10; int d7 = temp % 10; temp = temp / 10; int d6 = temp % 10; temp = temp / 10; int d5 = temp % 10; temp = temp / 10; int d4 = temp % 10; temp = temp / 10; int d3 = temp % 10; temp = temp / 10; int d2 = temp % 10; temp = temp / 10; int d1 = temp % 10; temp = temp / 10;
FULL Program (simpler parts left out)
//Have user enter 9 digit number ie. 123456789 int isbn = input.nextInt(); (INSERT ABOVE CODE HERE) //Calculate 10th digit int d10 = ((d1*1+d2*2+d3*3+d4*4+d5*5+d6*6+d7*7+d8*8+d9*9) % 11); //If 10th digit = 10, use X if (d10 == 10) System.out.println(d1+d2+d3+d4+d5+d6+d7+d8+d9+"X"); //Else print all 10 digits ie. 1234567890 else System.out.println(d1+d2+d3+d4+d5+d6+d7+d8+d9+d10);
=/ What am I doing to only get 2 digits on the output? Thanks for your patience and time.

New Topic/Question
Reply



MultiQuote





|