Advertisement
hpilo

Chapter6_Func_Ex2

Dec 15th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.util.Scanner;
  2. /*
  3. =====================================================
  4. chapter 6: Functions
  5.  
  6. Ex2:
  7. =====================================================
  8. */
  9.  
  10. public class MyProgram {
  11.  
  12. public static int createNumber(int a,int b){
  13. String result="";
  14. while(a>0 && b>0){
  15. result= String.valueOf((a%10<b%10) ? a%10: b%10)+result;
  16. a/=10;
  17. b/=10;
  18. if ((a==0 && b!=0) ||(a!=0 && b==0)){
  19. return -1;
  20. }
  21. }
  22. return Integer.parseInt(result);
  23. }
  24. public static void main(String[] args) {
  25. int a,b;
  26. int res;
  27. Scanner s=new Scanner(System.in);
  28. System.out.println("Enter 2 numbers: ");
  29. a=s.nextInt();
  30. b=s.nextInt();
  31. res=createNumber(a,b);
  32. System.out.println(res);
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement