Pages

Saturday, 24 December 2016

Problem 43 - Reverse Number

Program akan membalikan urutan angka dengan medote for looping

Source code program

DATA HOSTED WITH ♥ BY PASTEBIN.COM - DOWNLOAD RAW - SEE ORIGINAL
  1. import java.util.Scanner;
  2. class ForLoopReverseDemo
  3. {
  4.    public static void main(String args[])
  5.    {
  6.       int num=0;
  7.       int reversenum =0;
  8.       System.out.println("Input your number and press enter: ");
  9.       Scanner in = new Scanner(System.in);
  10.       num = in.nextInt();
  11.    
  12.       for( ;num != 0; )
  13.       {
  14.           reversenum = reversenum * 10;
  15.           reversenum = reversenum + num%10;
  16.           num = num/10;
  17.       }
  18.  
  19.       System.out.println("Reverse of specified number is: "+reversenum);
  20.    }
  21. }
Hasil output program

0 comments:

Post a Comment