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 int array java

import java.util.*;
import java.util.stream.Collectors;

int[] array = new int[] {23, 54, 12};
List<Integer> list = Arrays.stream(array).boxed().collect(Collectors.toList());
Collections.reverse(list);
array = list.stream().mapToInt(x -> x).toArray();
//array = [12,54,23]
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

Reverse int


bool is_palindrome(unsigned long long int num)
{
    int temp; // Will hold temporary nums as we strip off digits
    int remainder;
    unsigned long long int reversed=0;
    temp = num;
    while(temp>0)
    {
        remainder = temp%10;
        reversed = (reversed*10)+remainder;
        temp = temp/10;
    }
    if(reversed==num)
        return true;
    else
        return false;
}
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 :: java int 
Java :: get the max value from arrayList java and save it in int 
Java :: java csv line split 
Java :: java catch multiple exceptions 
Java :: declaration of double array in java 
Java :: get request in java 
Java :: timestamp to date java 
Java :: Java Converting int to double 
Java :: how to make java list 
Java :: Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: plugins.flutter.io/webview 
Java :: hello world java code 
Java :: intent pick action video android 
Java :: check if a string is empty java 
Java :: How to efficiently convert a sorted array into a min height binary search tree, in Java? 
Java :: spring boot base url 
Java :: List into string java 
Java :: java error message 
Java :: java string array initialization 
Java :: datatypes in java 
Java :: matrice java 
Java :: sorting in java 
Java :: cmd java compile 
Java :: java string to integer 
Java :: java wait(timeout) 
Java :: make edittext not editable android 
Java :: boucle for avec un tableau java 
Java :: add two numbers bitwise 
Java :: java inheritance 
Java :: how to display the decimal value when 0 after point android studio 
Java :: pyramid pattern program in java 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =