Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I am getting the following error,
prog.java:10: error: cannot find symbol
System.out.System.out.println("No string");


What I have tried:

I am trying the following code for this,
Java
class GFG {
	public static void main (String[] args) {
		String str= "gadag"; 
		if(str==null)
		{
		    System.out.System.out.println("No string");
		}
	   StringBuilder strBuilder = new StringBuilder(str);
		 strBuilder.reverse();
	     Boolean status = strBuilder.equals(str);
		 System.out.println(status);
		 
		}
	}
Posted
Updated 29-Jul-19 8:24am
v2

Just an idea:
Java
System.out.System.out.println("No string");

Did you read the code to try to understand what is wrong in this code ? or is it just easier to ask us ?
You should be able to find such error by yourself.
 
Share this answer
 
Why reverse the string? That's OK for little strings, but a serious waste of time and memory for large ones.
Instead, consider this: a string can be thought of as an array of characters, so you can use charAt(index) to return a single character.
If you loop through half as many characters as there are in the string, then you can compare the first with the last, the second with the second to last, ... all the way to the center. If you find a single difference, it's not a palindrome.
That way, you are using less memory, less processor, and it's generally a much better idea ... for real efficiency, use two indexes: one at the first char, one at the last, and move one up and one down each time round the loop.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900