new semester, new repo structure
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab12_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Palindrome1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Create a Scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt the user to enter a string
|
||||
System.out.print("Enter a string: ");
|
||||
String s = input.nextLine();
|
||||
|
||||
// The index of the first character in the string
|
||||
int low = 0;
|
||||
|
||||
// The index of the last character in the string
|
||||
int high = s.length() - 1;
|
||||
|
||||
boolean isPalindrome = true;
|
||||
while (low < high) {
|
||||
if (s.charAt(low) != s.charAt(high)) {
|
||||
isPalindrome = false;
|
||||
break;
|
||||
}
|
||||
|
||||
low++;
|
||||
high--;
|
||||
}
|
||||
if (isPalindrome) {
|
||||
System.out.println(s + " is a palindrome");
|
||||
} else {
|
||||
System.out.println(s + " is not a palindrome");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user