Recent Posts
SeC Gaming
the Lounge
New Lounge Topic
New Gaming Topic
We've moved to Discord

You are not connected. Please login or register

anybody good with java?

2 posters

Go down  Message [Page 1 of 1]

1anybody good with java? Empty anybody good with java? 2012-02-06, 01:10

BmmFlash

BmmFlash

My assignment is as follows=
write a program that:
-prompts the User for a 2 digit positive integer that does not end in zero
-displays the sum of the numbers divisible by the second digit that are less than the imputed number

Example:
User enters 25, outputs 50 (5+10+15+20)
enter 26, outputs 60 (6+12+18+24)
enter 11, output 55 (1+2+3+4+5+6+7+8+9+10)


Basically, I forgot how to seperate the two digit integer. I know there's something you can do with the string class, or dividing by a multiple of 10, I just cant for the life of me remember what :/
other than that, it should just be a loop. I'm blanking so bad though.
Would something like this work? I'm using the 25 example

//num is the imputed integer
for(I=1; I<=divisors; I++)
// divisors is the quotient of num and the second number, an integer.
{
multiple=secondNum*I;
System.out.println(multiple);
sum=sum+multiple;
}

I know I skipped a lot, but basically secondNum would have the second number. Multiple would be the second number times I, which is incrementing from 1 to the amount of times secondNum goes into the imputed number. Sum is the easy part.
basically, all I need to know is how to get the god damn secondNum Sad

2anybody good with java? Empty Re: anybody good with java? 2012-02-06, 03:07

Bla125

Bla125

Tip, ask Khult Very Happy

3anybody good with java? Empty Re: anybody good with java? 2012-02-06, 03:18

Bla125

Bla125

But you want to know how to separate the two digit integer? What comes to mind is to convert it into a string and use substring. Or wouldn't getCharArray or whatever work?

I'm sure there's something on Google but I'm too lazy and don't want to hand you code that I don't understand. Khult knows a LOT about Java though. I always go to him for help.

4anybody good with java? Empty Re: anybody good with java? 2012-02-06, 09:11

BmmFlash

BmmFlash

I remember something about char array, just not enough to actually use it. The last one we did like this our teach divided by like 100000000, but that was to seperate a phone number. Gaahh, I should of wrote that down, lol

5anybody good with java? Empty Re: anybody good with java? 2012-02-06, 09:52

BmmFlash

BmmFlash

Got it! It was modular division by ten.
Soooooooo,

Sop("please give me a positive number not ending in zero");
//sop is short for system.out.println, cuz I'm lazy ;D
Int inputNum=input.nextInt();
int secondNum=imputNum%10;
int divisors=(inputNum/secondNum)-1;
int multiple=0;
int sum=0;
int I=0;
for(I=1; I<=divisors; I++)
{
multiple=secondNum*I;
Sop(multiple);
sum=sum+multiple;
}
Sop(sum);

6anybody good with java? Empty Re: anybody good with java? 2012-02-07, 02:00

Bla125

Bla125

Nice! Didn't think of that.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum