Skip to main content

Write a program to reverse all the digits of a given integer.

Write a program to reverse all the digits of a given integer.



import java.util.Scanner; 
class assignment1{ 
public static void main(String[] args) { 
Scanner sc = new Scanner(System.in); 
System.out.println("Enter the number : "); 
int n = sc.nextInt(); 
reverseNum(n); 
sc.close(); 
public static void reverseNum(int num) { 
int n = num; 
int rev = 0; 
while (n > 0) { 
int rem = n % 10; 
rev = rev * 10 + rem; 
n /= 10; 
System.out.println("Reverse of " + num + " is " + rev); 
}


OUTPUT:

Enter the number :
1234
Reverse of 1234 is 4321


Comments

Popular posts from this blog

DBMS Keys

DBMS Keys KEYS in DBMS is an attribute or set of attributes which helps you to identify a row (tuple) uniquely in a relation(table). They allow you to find the relation between two tables. Keys help you uniquely identify a row in a table by a combination of one or more columns in that table. Key is also helpful for finding unique record or row from the table. Database key is also helpful for finding unique record or row from the table. Example: Employee ID FirstName LastName 11 Andrew Johnson 22 Tom Wood 33 Alex Hale In the above-given example, employee ID is a primary key because it uniquely identifies an employee record. In this table, no other employee can have the same employee ID. Here are some reasons for using sql key in the DBMS system. Keys help you to identify any row of data in a table. In a real-world application, a table could contain thousands of records. Moreover, the records could be duplicated. Keys in RDBMS ensure that you can uniquely identify a table record despite ...

four methods overload these methods

Write a program in java which has the following classes and methods:  Class : OverloadDemo Methods : test() Declare four methods with the same name “test()” and overload these methods class OverloadDemo{  public void test(){  System.out.println("It's a test method for null.");  }  public void test(int n){  System.out.println("It's a test method for displaying the int value "+n);  }  public void test(double d){  System.out.println("It's a test method for displaying the double value "+d);  }  public void test(String s){  System.out.println("It's a test method for displaying the String "+s);  }  }  class overClass{  public static void main(String[] args) {  OverloadDemo old = new OverloadDemo();  old.test();  old.test(12);  old.test(25.35);  old.test("Subham");  }  } OUTPUT: It's a test method for null. It's a test method for displaying the int value 12 It's a test method for ...

Implement Echo client and Echo server using TCP Sockets

Implement Echo client and Echo server using TCP Sockets EchoServer.java import java.net.*; import java.io.*; public class EServer { public static void main(String args[]) { ServerSocket s=null; String line; DataInputStream is; PrintStream ps; Socket c=null; try { s=new ServerSocket(9000); } catch(IOException e) {} try { System.out.println(e); c=s.accept(); is=new DataInputStream(c.getInputStream()); ps=new PrintStream(c.getOutputStream()); while(true) { line=is.readLine(); ps.println(line); }} catch(IOException e) { System.out.println(e); }}} EchoClient.java import java.net.*; import java.io.*; public class EClient { public static void main(String arg[]) { Socket c=null; String line; DataInputStream is,is1; PrintStream os; try { InetAddress ia = InetAddress.getLocalHost(); c=new Socket(ia,9000); } catch(IOException e) {} try { System.out.println(e); os=new PrintStream(c.getOutputStream()); is=new DataInputStream(System.in); is1=new DataInputStream(c.getInputStream()); while(true) { Sys...