d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Iso Help With A Java Prob
Prev1234Next
Add Reply New Topic New Poll
Member
Posts: 6,604
Joined: May 29 2013
Gold: 2.72
Oct 1 2014 10:14pm
Alright, this is one that I have just no clue how to do.

I have to enter 2 numbers, and multiplicate them 2 together.

Let's say I pick 4 and 50. It will give 200 .... but it needs to display like this : 50 + 50 + 50 + 50 = 200 and not 4*50 = 200.

It also has to take the shorter rout .... so 50+50+50+50 and not 4+4+4+4+4+4+4..... up to 50 times..
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 1 2014 10:21pm
Quote (Jibbosh @ Oct 2 2014 12:14am)
Alright, this is one that I have just no clue how to do.

I have to enter 2 numbers, and multiplicate them 2 together.

Let's say I pick 4 and 50. It will give  200 .... but it needs to display like this : 50 + 50 + 50 + 50 = 200 and not 4*50 = 200.

It also has to take the shorter rout .... so 50+50+50+50 and not 4+4+4+4+4+4+4..... up to 50 times..


you keep saying you have no clue.

lets start simple.

how do you determine which path is shorter? show me code.
Member
Posts: 6,604
Joined: May 29 2013
Gold: 2.72
Oct 1 2014 10:30pm
Quote (carteblanche @ Oct 2 2014 12:21am)
you keep saying you have no clue.

lets start simple.

how do you determine which path is shorter? show me code.


This one I have no clue, the others, I was already on a good path and I was always close of being correct.

I've done over 20 tonight, some are just harder for me since im just starting. Like this one.
Member
Posts: 6,562
Joined: Oct 29 2007
Gold: 4.00
Oct 1 2014 10:34pm
so just start out not worrying about printing. how do you actually do the calculation in this way.

to see the shorter route you need to determine which number is smaller, right?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 1 2014 10:36pm
Quote (Jibbosh @ Oct 2 2014 12:30am)
This one I have no clue, the others, I was already on a good path and I was always close of being correct.

I've done over 20 tonight, some are just harder for me since im just starting. Like this one.


lets start simple then. for clarty, we'll use this notation: base + base + base + ... + base

ex:

2x3:
base 2 => 2 + 2 +2
base 3 => 3 + 3

which has the shorter chain? base 3

lets try a few examples. for each one, which base creates the shorter chain?

1x4
2x4
3x4
5x4

6x4


now explain your results. something special happens at the bolded pair. explain what it is

This post was edited by carteblanche on Oct 1 2014 10:37pm
Member
Posts: 6,604
Joined: May 29 2013
Gold: 2.72
Oct 1 2014 10:49pm
Quote (carteblanche @ Oct 2 2014 12:36am)
lets start simple then. for clarty, we'll use this notation: base + base + base + ... + base

ex:

2x3:
base 2 => 2 + 2 +2
base 3 => 3 + 3

which has the shorter chain? base 3

lets try a few examples. for each one, which base creates the shorter chain?

1x4
2x4
3x4
5x4

6x4


now explain your results. something special happens at the bolded pair. explain what it is


well... 3x4 it's 4+4+4

and 5x4 its 5+5+5+5

So I guess that .... it takes the biggest number of the 2, and it makes an addition ... 3 times ... , that's pretty much what I don't understand how to do. I get it, how to get the biggest number.

But now I have to tell him to do it "x" number of times which "x" is the smallest number..
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 1 2014 10:53pm
Quote (Jibbosh @ Oct 2 2014 12:49am)
well... 3x4 it's 4+4+4

and 5x4 its 5+5+5+5

So I guess that .... it takes the biggest number of the 2, and it makes an addition ...  3 times ... , that's pretty much what I don't understand how to do. I get it, how to get the biggest number.

But now I have to tell him to do it "x" number of times which "x" is the smallest number..


Excellent, now we have a starting spot based on what you said

Code
private void printMultiplication(int a, int b){
int base = // pick the biggest of a and b
int repeatCount = // pick the smallest of a and b
String output = "";

// repeat this #repeatCount times:
{
// add base and some punctuation to output
}
// print out the output
}


now write some code to fill in the template.

eg: do you know anything in java that will repeat code a fixed number of times?
how do you determine which integer is bigger than the other?

This post was edited by carteblanche on Oct 1 2014 10:57pm
Member
Posts: 6,604
Joined: May 29 2013
Gold: 2.72
Oct 1 2014 11:04pm
Quote (carteblanche @ Oct 2 2014 12:53am)
Excellent, now we have a starting spot based on what you said

Code
private void printMultiplication(int a, int b){
    int base = // pick the biggest of a and b
    int repeatCount = // pick the smallest of a and b
    String output = "";

    // repeat this #repeatCount times:
    {
          // add base and some punctuation to output
    }
    // print out the output
}


now write some code to fill in the template.

eg: do you know anything in java that will repeat code a fixed number of times?
how do you determine which integer is bigger than the other?


Well. would that FOR function work?

and if it would be with a for, to find the bigger I would do ...

int iNbMax = 0
int iNb

and in my FOR function, I would do an IF ( would pass both numbers in there and ... the highest would stay.

if ( iNb > iNoteMax ){
iNoteMax = iNote;}
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 1 2014 11:09pm
Quote (Jibbosh @ Oct 2 2014 01:04am)

and if it would be with a for, to find the bigger I would do ...

int iNbMax = 0
int iNb

if ( iNb > iNoteMax ){
    iNoteMax = iNote;}


close, but not exactly. why are you choosing 0 as the starting point? you have two perfectly good inputs to begin with. how ab out choose one of them to start with, and change it if the other is bigger?
Member
Posts: 6,604
Joined: May 29 2013
Gold: 2.72
Oct 1 2014 11:16pm
Quote (carteblanche @ Oct 2 2014 01:09am)
close, but not exactly. why are you choosing 0 as the starting point? you have two perfectly good inputs to begin with. how ab out choose one of them to start with, and change it if the other is bigger?


Well, my idea about that is to get NbMax the lowest .. number possible if you don't go in the negative...

So if I enter a number after that, it will for sure take the place of iNbMax..

so if I enter "6"

iNbMax will be equal to 6 until a new higher number takes his place.
Go Back To Programming & Development Topic List
Prev1234Next
Add Reply New Topic New Poll