java - Returning multiple ints as a single value -
hey i'm working on method picks smallest digit ones, tens, hundreds, , thousands place on 2 passed integers , returns int made of smallest values each place. example if int a= 4321 , int b=1957 method return 1321. code far, think got cant find out how return new value integer.
public static int biggestloser(int a, int b){ int first; int second; int third; int fourth; if(a>9999 || a<1000 || b>9999 || b<1000){ if(a>b) return b; else return a; } else{ if(a%10 < b%10) first=a%10; else first=b%10; if(a/1000<b/1000) fourth=a/1000; else fourth=b/1000; if(a/100%10<b/100%10) second=a/100%10; else second=b/100%10; if(a/10%10<b/10%10) third=a/10%10; else third=b/10%10; //int total=fourth,third,second,first;????? //return total; } }
first of code has minor error. have swap codes second
, third
.
if(a/100%10<b/100%10) third=a/100%10; else third=b/100%10; if(a/10%10<b/10%10) second=a/10%10; else second=b/10%10;
after fixing say:
int total = first + 10 * second + 100 * third + 1000 * fourth; return total;
and that's it.
Comments
Post a Comment