“Nomor terbalik di Java” Kode Jawaban

Nomor terbalik di 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();
    }
}
Poised Parrot

membalikkan bilangan bulat di java

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

cara membalikkan angka di java

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

Nomor terbalik di 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);
  }
}
Different Dragonfly

cara membalikkan angka di 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);
    }
Chathumal Sangeeth

Jawaban yang mirip dengan “Nomor terbalik di Java”

Pertanyaan yang mirip dengan “Nomor terbalik di Java”

Lebih banyak jawaban terkait untuk “Nomor terbalik di Java” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya