#the digits of the number formed strictly decrease from left to right
1 messages · Page 1 of 1 (latest)
to get the median you can do like
(x + y + z) - (min + max)
I was struggling for the middle also 😄
a bunch of if/else is easier
or just sort List<Integer>
@foggy falcon @drifting ocean thank you! I will try both ways :D
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
Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
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
thank you!
urwelcome
seriously, use sort() or if/else in production code 🤣
I guess the exercice was to make you think of sorting before teaching you sorting
yes T^T
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?
missing a +
This if/else is broken, but work in progress 😄
https://onlinegdb.com/YMun75Tsb
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 :,)
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
Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
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