Jiyoung Kim

Greenhorn

Posts: 15

posted 7 months ago

I'm trying to get the biggest number in a string that is contained in numbers and operators randomly.

For example, -123456789 will be (98765432-1), 1234567890 will be (9876543210), 123*456+7 will be (765*432 + 1), and so on.

However, I have no idea how to split the operators and the numbers and find the operation that makes the biggest numbers.

This is a method to find and calculate the number.

And, what I'm trying to do is to make separated between operators and numbers using ArrayList above.

But, is it available to make the operations in this approach? I guess that I need to find the operations in a string without a split.

I know how to organize the numbers from the highest to the lowest in a string like below.

The quetsion is kind of messy, but could you provide some instructions how to approach?

Input

12356789

-123456789

123*456+7

Output

987654321

987665432-1 = ?

(765*432)+1 = ?

For example, -123456789 will be (98765432-1), 1234567890 will be (9876543210), 123*456+7 will be (765*432 + 1), and so on.

However, I have no idea how to split the operators and the numbers and find the operation that makes the biggest numbers.

This is a method to find and calculate the number.

And, what I'm trying to do is to make separated between operators and numbers using ArrayList above.

But, is it available to make the operations in this approach? I guess that I need to find the operations in a string without a split.

I know how to organize the numbers from the highest to the lowest in a string like below.

The quetsion is kind of messy, but could you provide some instructions how to approach?

Input

12356789

-123456789

123*456+7

Output

987654321

987665432-1 = ?

(765*432)+1 = ?

Campbell Ritchie

Marshal

Posts: 56584

172

posted 7 months ago

Divide and rule. That question looks like something which should be broken down into parts. Start by describing how you would work out the largest number formed from the digits 1234567890. Also look at this Unicode link to remind yourself how the ten digits 123456890 are represented in ASCII: do the ASCII numbers an the values of the digits always run in the same order?

posted 7 months ago

Why would an input of

What exactly are the rules you need to follow to determine "largest number formed from the digits"? It seems to me that it's not only just the digits that you have to use but also the operations that would affect how large the number is that you can get.

`123*456+7`give an output of`765*432+1`? Following normal math operator order of precedence (MDAS), the output expression evaluates to 330481. However,`7*65432+1`, which uses the same digits and operations, will evaluate to 458025, which is greater.What exactly are the rules you need to follow to determine "largest number formed from the digits"? It seems to me that it's not only just the digits that you have to use but also the operations that would affect how large the number is that you can get.

*Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

posted 7 months ago

I would suggest you stop worrying about Java entirely until you have this worked out on paper. This is really the crux of the issue. Once you know how to do this, writing the code is the easy part.

Jiyoung Kim wrote:I have no idea how to split the operators and the numbers and find the operation that makes the biggest numbers.

I would suggest you stop worrying about Java entirely until you have this worked out on paper. This is really the crux of the issue. Once you know how to do this, writing the code is the easy part.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors