Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java code to reverse an integer

public class ReverseNumberExample1   
{  
public static void main(String[] args)   
{  
int number = 987654, reverse = 0;  
while(number != 0)   
{  
int remainder = number % 10;  
reverse = reverse * 10 + remainder;  
number = number/10;  
}  
System.out.println("The reverse of the given number is: " + reverse);  
}  
}  
Comment

reverse a integer in java

while(num != 0) 
{
   int digit = num % 10;
   reversed = reversed * 10 + digit;
   num /= 10;
}
Comment

reverse number in java

import java.util.*;
class reverse
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter String: ");
        String str = sc.next();
        char d;
        String str2 = "";
        int l = str.length();
        for(int i = l-1; i >= 0; i--)
        {
            d = str.charAt(i);
            str2 = str2 + d;
        }
        System.out.println(str2);
        sc.close();
    }
}
Comment

how to reverse a number in java

int rev= 0;
while(num > 9)
{
  rev= rev*10 + num%10;
  num/= 10;
}
Comment

reverse number in java

class Main {
  public static void main(String[] args) {

    int num = 1234, reversed = 0;
    
    System.out.println("Original Number: " + num);

    // run loop until num becomes 0
    while(num != 0) {
    
      // get last digit from num
      int digit = num % 10;
      reversed = reversed * 10 + digit;

      // remove the last digit from num
      num /= 10;
    }

    System.out.println("Reversed Number: " + reversed);
  }
}
Comment

how to reverse numbers in java

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();

        int rev = 0;

        while (num > 0) {
            rev = rev * 10 + num % 10;
            num /= 10;
        }
        System.out.println(rev);
    }
Comment

reverse number java

import java.util.Scanner;

public class App1 {
    public static void main(String[] args) {
        Scanner scannerNum = new Scanner((System.in));
        int number , sum = 0;
        number = scannerNum.nextInt();

       
        System.out.println("sum = " + sum);*/
        int result = 0 , digit;
        while(number != 0)
        {
            result *= 10;
            digit = number % 10;
            result += digit;
            number = number / 10;
        }
        System.out.println("result = " + result);


    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: where is java in ubuntu 
Java :: java pattern check 
Java :: javafx get the controller of a pane 
Java :: $JAVA_HOME ENV 
Java :: java initialize object array 
Java :: retrofit 
Java :: get index of element in array java 
Java :: tableau de chaîne de caractère en java 
Java :: File Appender log4j2.properties spring 
Java :: java arraylist with double 
Java :: destory fragment 
Java :: debug in java 
Java :: latest android sdk version 
Java :: Java Hashmap Add Elements 
Java :: java stringbuilder setcharat 
Java :: print all numbers from 1 to n java 
Java :: do while jaca 
Java :: simple for loop 
Java :: java ints to color int 
Java :: spring properties list 
Java :: Number to decimal places in java 
Java :: public static void main(String[] args) in java 
Java :: gui open event spigot 
Java :: alphabet n vowelin java 
Java :: java stream inner join two lists 
Java :: default java keystore 
Java :: jsp check if request parameter exists 
Java :: declare id in java 
Java :: java array merge 
Java :: java.lang.double cannot be cast to java.lang.float 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =