hpilo

Chapter6_Func_Ex1

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