reverse array in java
int length = array.length;
for(int i=0;i<length/2;i++) {
int swap = array[i];
array[i] = array[length-i-1];
array[length-i-1] = swap;
}
or
Collections.reverse(Arrays.asList(array));
reverse array in java
int length = array.length;
for(int i=0;i<length/2;i++) {
int swap = array[i];
array[i] = array[length-i-1];
array[length-i-1] = swap;
}
or
Collections.reverse(Arrays.asList(array));
reverse a string in java
public class Main {
public static void main(String[] args) {
// Write a Java program to reverse a string.
Scanner input = new Scanner(System.in);
System.out.println("Enter the String:");
char[] letters = input.nextLine().toCharArray();
System.out.println(" Reverse String");
for(int i = letters.length -1; i >= 0; i--){
System.out.print(letters[i]);
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us