Answer to Question #314351 in Java | JSP | JSF for yash

Question #314351

Write a program that takes a String

through Command Line argument and display the length of

the string. Also display the string into uppercase and check whether it is a palindrome or not.



1
Expert's answer
2022-03-19T08:52:24-0400
public class App {
	/** Main Method */
	public static void main(String[] args) {
		if (args.length > 0) {
			String string = "";
			for (int i = 0; i < args.length; i++) {
				string += args[i];
			}
			System.out.println("The length of the string: " + string.length());
			System.out.println("The string into uppercase: " + string.toUpperCase());
			if (isPalindrome(string)) {
				System.out.println(string + " is a palindrome");
			} else {
				System.out.println(string + " is not a palindrome");
			}
		} else {
			System.out.println("Invalid input");
		}
	}


	static boolean isPalindrome(String word) {
		int index = 0;
		int length = word.length() - 1;
		while (length > index) {
			if (word.charAt(index) != word.charAt(length)) {
				return false;
			}
			index++;
			length--;
		}
		return true;
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS