140,902 views
28 votes
28 votes
Write a Program that prints a given string in reverse order using a while loop

Use that same program to check if the given string is a pallindrome or not?

USE JAVA PLS
75 POINTS NEED QUICK PLEASE

User Alfons
by
2.5k points

1 Answer

23 votes
23 votes

import java.util.*;

class HelloWorld {

public static void main(String[] args) {

System.out.println("Please enter a string: ");

Scanner idx = new Scanner(System.in);

String f = idx.nextLine(),n="";

int c=0;

while(c<f.length()) {

char temp = f.charAt(c);

n=temp+n;

c++;

}

System.out.println("Reversed: "+n);

}

}

User Athena Wisdom
by
2.5k points