Add HW01 exercises
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import java.util.Scanner;
|
||||
public class Palindrome {
|
||||
static boolean isPalin(String s){
|
||||
int i = 0;
|
||||
int j = s.length()-1;
|
||||
|
||||
while (i < j) {
|
||||
if (s.charAt(i) != s.charAt(j)){
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public static void main(String[] args){
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String str = sc.nextLine();
|
||||
|
||||
boolean isPal = isPalin(str);
|
||||
System.out.println("is "+ str+ " palindrome? "+ isPal);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user