Original Post
Im trying to help a friend who just started a java class, and we are a bit stuck. We thought we had the first problem but it wont add up to what its supposed to. And for the second project we are just completely lost. Anyway here is the first program, its supposed to randomly generate 5 numbers and add them together. class problem Problem 2, this one we were completely lost on. Write a program to randomly generate a 3-digit number N (it is ok if the number has fewer than 3 digits). Create a number NN which is N placed next to it. Example if the number N is 263 then NN is 263263. If N is 7, NN is 007007. If N is 032, NN is 32032. Next Divide NN by 7, and then by 11 and then 13 Write the original number and the final result after the divisions. Formula to randomly generate a 3-digit number is (int)Math.floor(Math.random()*1000+1) [Edited by - Narusuke on October 9, 2009 12:38:56 PM]
{
public static void main(String[] args)
{
int number, x = (int)Math.floor(Math.random()*100000+1);
int sum = 0;
int digit;
number = x;
x = x/10;
digit = x % 10;
sum += digit;
x = x/10;
digit = x % 10;
sum += digit;
x = x/10;
digit = x % 10;
sum = x/10;
x = x/10;
digit = x % 10;
sum += digit;
x = x/10;
digit = x % 10;
sum += digit;
System.out.printf("Gien number =%6d and the sum of digits = %6d", number, sum);
}
}