Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- =====================================================
- chapter 6: Functions
- Ex1:
- =====================================================
- */
- public class MyProgram {
- public static int incDigits(int num){
- String result="";
- while(num>0){
- if(num%10!=9)
- result=((num%10)+1)+result;
- else
- result="0"+result;
- num/=10;
- }
- return Integer.parseInt(result);
- }
- public static void main(String[] args) {
- int num;
- int res;
- Scanner s=new Scanner(System.in);
- System.out.println("Enter a number: ");
- num=s.nextInt();
- res=incDigits(num);
- System.out.println("number: "+ num+"\t\tnew number: "+res);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment