Code Coach It’s a sign | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Code Coach It’s a sign

/*Java - Can this be optimised even further -*/ import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String entry[] = new String[4]; for (int i = 0; i < entry.length; i++) { entry[i] = scan.next().toUpperCase(); } String[] reversed = new String[4]; for (int i = 0; i < entry.length; i++) { char[] temp = entry[i].toCharArray(); char[] temp2 = new char[temp.length]; for (int j = 0; j < temp.length; j++) { temp2[(temp.length - 1) - j] = temp[j]; } reversed[i] = String.valueOf(temp2); } if (Arraycheck(entry, reversed)) { System.out.println("Open"); } else System.out.println("Trash"); } static Boolean Arraycheck(String[] original, String[] reversed) { for (int i = 0; i < original.length; i++) { for (int j = 0; j < reversed.length; j++) { if (original[i].equals(reversed[j])) { return true; } } } return false; } }

22nd Nov 2022, 8:24 AM
Isuru
Isuru - avatar
4 Answers
+ 2
That said, you can skip the creation of an array with reversed strings, and use a similar logic to compare each character with the one in the mirrored position.
22nd Nov 2022, 2:19 PM
Emerson Prado
Emerson Prado - avatar
+ 2
Isuru what's your doubt?
22nd Nov 2022, 8:35 AM
Sakshi
Sakshi - avatar
+ 2
Isuru Pls improve your question by: 1. Removing the wall of code in the question description, saving it in Code Playground, then adding a link to it (use "+" button) in the question description again. 2. Stating your requests in the question description too, not in an answer, where it can get lost if there are many others.
22nd Nov 2022, 2:17 PM
Emerson Prado
Emerson Prado - avatar
0
Hi Sakshi got any idea about writing the code using few lines.. I think code has too much lines
22nd Nov 2022, 8:36 AM
Isuru
Isuru - avatar