I am comparing a string with the same string just reversed. It is working fine until the number i compare is bigger then 10 char. Why?
import java.util.Scanner;
public class A {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int level = sc.nextInt();
if (level >= 1 && level <= 20) {
// System.out.println(level);
}
sc.nextLine();
String reverse = "";
String line1 = sc.nextLine();
String line2 = sc.nextLine();
// Reverse
for(int i = line1.length() - 1; i >= 0; i--)
{
reverse = reverse + line1.charAt(i);
}
if(reverse.equals(line2)){
System.out.println("Deletion succeeded");
}
else{
System.out.println("Deletion failed");
}
}
}
Aucun commentaire:
Enregistrer un commentaire