Need help with this task. How can i Compare line two and line three where line three need to be the reverse off line two to print out succeeded?
input:
The first line of the input contains a single integer 1≤≤20. The two following lines each contain a string containing only the characters 0 and 1. The first of these lines represent the bits of the file before deletion and the second the bits on the same position on the hard drive after the file has been deleted. The length of these strings are the same and between 1 and 1000 characters.
output:
Output a single line containing either the words “Deletion succeeded” if each bit is switched times or “Deletion failed” if this is not the case.
So the input will be something like this:
1
10001110101000001111010100001110
01110001010111110000101011110001
and if line two and three i the same(just det third line is reversed from line two) then the output will be:
Deletion succeeded
if input is this:
20
0001100011001010
0001000011000100
Where line two and three is not the same, then the output will be:
Deletion failed
Note that line one can only consist off number 1 to 20 and line two and three only off a string with 1 and 0.
This is what i have:
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);
}
String reverse = "";
String validering;
String line1 = sc.next();
String line2 = sc.next();
// Reverse
for(int i = line1.length() - 1; i >= 0; i--)
{
reverse = reverse + line1.charAt(i);
}
System.out.print(reverse);
if (line1.equals(reverse)) {
System.out.println("Deletion succeeded");
}
else if (!line1.equals(reverse)) {
System.out.println("Deletion failed");
}
}
}