Restore
This commit is contained in:
10
Labs/Lab2/Lab2Part2_2230026071/Question3/.classpath
Normal file
10
Labs/Lab2/Lab2Part2_2230026071/Question3/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
Labs/Lab2/Lab2Part2_2230026071/Question3/.project
Normal file
17
Labs/Lab2/Lab2Part2_2230026071/Question3/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Question3</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
Binary file not shown.
@@ -0,0 +1,35 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a String: ");
|
||||
Scanner in = new Scanner(System.in);
|
||||
String inStr = in.nextLine(); // read string
|
||||
String lowStr = inStr.toLowerCase(); // convert to lowercase
|
||||
|
||||
int fIdx = 0, bIdx = inStr.length() - 1; // forward & backward indexes
|
||||
char fChar, bChar; // forward & backward characters
|
||||
while(fIdx < bIdx) {
|
||||
fChar = lowStr.charAt(fIdx);
|
||||
bChar = lowStr.charAt(bIdx);
|
||||
if(!Character.isLetter(fChar)) { //when it is not a letter, adjust index
|
||||
fIdx++;
|
||||
continue;
|
||||
}
|
||||
if(!Character.isLetter(bChar)) {
|
||||
bIdx--;
|
||||
continue;
|
||||
}
|
||||
if(fChar != bChar) {
|
||||
System.out.println("\"" + inStr + "\" is not a palindrome");
|
||||
return;
|
||||
} else { // match, change index
|
||||
fIdx++;
|
||||
bIdx--;
|
||||
}
|
||||
}
|
||||
System.out.println("\"" + inStr + "\" is a palindrome");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user