reverse number (java program pdf)

1
Class reverse 1/1 /* * [email protected] * javaprogramsbyashking13th.blogspot.in * ashkingjava.blogspot.in * * QUESTION * * Design a program in java to find the reverse of a number. * eg if * input 123 then * output should be 321 */ import java.io.*; public class reverse { public void main(int n) throws IOException //method to create reverse of a number { int m=n; //creating dummy variable int r=0; int s=0; while(m>0) //loop condition { r=m%10; //last digit extraction s=(s*10)+r; //creating reverse number m=m/10; //updating loop variable } System.out.println("original number\t"+n); System.out.println("reverse number\t"+s); } } Mar 25, 2014 3:23:43 PM

Upload: amrendra-singh

Post on 28-Dec-2015

40 views

Category:

Documents


2 download

DESCRIPTION

JAVA PROGRAM TO FIND THE REVERSE OF A NUMBER. WITH COMMENTS AND DETAILS TO HELP YOU UNDERSTAND THEM.THIS PROGRAM HAS BEEN RUN ON BlueJ AND IS ERROR FREE.IT WILL SURELY HELP YOU IN STUDYING JAVA PROGRAMS FOR EXAMS OR OTHERWISE.

TRANSCRIPT

Page 1: Reverse Number (JAVA PROGRAM pdf)

Class reverse 1/1

/* * [email protected] * javaprogramsbyashking13th.blogspot.in * ashkingjava.blogspot.in * * QUESTION * * Design a program in java to find the reverse of a number. * eg if * input 123 then * output should be 321 */

import java.io.*;public class reverse{public void main(int n) throws IOException //method to create reverse of a number { int m=n; //creating dummy variable int r=0; int s=0; while(m>0) //loop condition { r=m%10; //last digit extraction s=(s*10)+r; //creating reverse number m=m/10; //updating loop variable } System.out.println("original number\t"+n); System.out.println("reverse number\t"+s); }}

Mar 25, 2014 3:23:43 PM