Answers for "reverse all java"

5

reverse number in java

public class ReverseNumber {
    public static void main(String[] args) {
        int num = 1234, reversed = 0;

        while(num != 0) {
            int digit = num % 10;
            reversed = reversed * 10 + digit;
            num = num / 10;
        }
        System.out.println("Reversed Number: " + reversed);
}}
Posted by: Guest on May-25-2020
2

java string reverse

String str = "Reverse this strings";
//for loop
for (int i = str.length() - 1; i >= 0; i--) {
	System.out.print(str.charAt(i));
}

// StringBuffer for multi thread
StringBuffer sb = new StringBuffer(); 
sb.append(str);
System.out.print(sb.reverse().toString());

// StringBuffer for single thread
StringBuilder sb = new StringBuilder(); 
sb.append(str);
System.out.print(sb.reverse().toString());
Posted by: Guest on June-01-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language