• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

why its not given any output?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class GFG {
   public static void main (String[] args) {
       
StringBuffer a=new StringBuffer();
StringBuffer b=a.reverse();


   if(a==b){
       int i,j;
      String f=a.toString();
    char []c=f.toCharArray();
    char []d=c;
    int n=a.length();
    int n1=n/2;
    for( i=0;i<n1;i++){
        d[i]=c[i+1];
        System.out.println(d);
    }
   }
   else{
     System.out.println("given string is not palindrome");
   }
   }
   }
 
Rancher
Posts: 5035
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard to read and understand the poorly formatted code you have posted.
If none of the print statements are being executed, then the if statement that controls their execution must be false.

The == operator for object references returns true if the two operands refer to the same object.  It looks like a and b refer to different objects and are not the same.
Use the equals() method to test if the contents of two objects is the same.
 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic