#the digits of the number formed strictly decrease from left to right

1 messages · Page 1 of 1 (latest)

steep stump
#

How can I do this using 3 integers and using Math.max and Math.min?
( I want 3 number to display as output)

There is an example run of this and what I have to far! :)
Thank you!

drifting ocean
#

swap the int as you math.max

#

Think Sort 😄

foggy falcon
drifting ocean
#

I was struggling for the middle also 😄

#

a bunch of if/else is easier

#

or just sort List<Integer>

steep stump
#

@foggy falcon @drifting ocean thank you! I will try both ways :D

drifting ocean
#

public static final String convert1(int x, int y, int z)
    {
        // first is max(x,y,z)
        final int maxXY = Math.max(x, y);
        final int first = Math.max(maxXY, z);
        
         // last is min(x,y,z)
        final int minYZ = Math.min(y, z);
        final int last  = Math.min(x, minYZ);
 
        final int maxXZ = Math.max(x, z);
        final int maxYZ = Math.max(y, z);

        // middle is not the first, so min of all max
        int middle = Math.min(first, maxXY);
        middle = Math.min(middle, maxYZ);
        middle = Math.min(middle, maxXZ);
       
        String s = "" + first + middle + last;
        return s;
    }
#

this works

#
#
    public static String convertListSort(int x, int y, int z)
    {
        final int[] row = new int[] { x, y, z };
        Arrays.sort(row);

        String s = "";
        for(int i : row)
        {
            s = i + s; //!< Reverse order
        }
        return s;
    }
#

using Arrays.sort(int[]) is much simpler 😄

#

here you go @steep stump

steep stump
drifting ocean
#

seriously, use sort() or if/else in production code 🤣

#

I guess the exercice was to make you think of sorting before teaching you sorting

drifting ocean
#

because 9 if/else jump is not super fast

#

ideal would be 3

steep stump
#

System.out.println(a + "-" + b "=" + c);

#

why am i getting a syntax error on "=" ? 👀

#

or is this not a good way to print out the equation?

drifting ocean
#

missing a +

steep stump
#

I have one last issue that i am struggling with T^T

#

do i make a new post?

#

and again, thank you so much! it's difficult to proper ways to get help especially as a newbie :,)

drifting ocean
#
    public static int[] extract(int c)
    {
        int left = c;
        
        int z = left % 10;
        left -= z;
        left /= 10;
        
        int y = left % 10;
        left -= y;
        left /= 10;

        int x = left % 10;
        
        int[] arr = new int[] {x,y,z};
        
        //System.out.println(Arrays.asList(x,y,z));
        
        return arr;
    }
#

using modulo @steep stump

#
steep stump
#

thank you thank you!!

drifting ocean
#

grade 6 math

#

modulo is the reminder of the division

#

c= 514 then z = 514 % 10 = 4

#

514-4 = 510

#

510/10 = 51

#

y = 51 % 10 = 1

steep stump
#

im ngl, once i see all these symbols, i feel like it's beyond me 💀 but i see it!

#

thanks :,)

drifting ocean
#

51 - 1 = 50

#

50 / 10 = 5

#

x = 5 % 10 = 5

#

c = 514 then { x, y, z } = { 5, 1, 4 }