0% found this document useful (0 votes)
2 views3 pages

String&Class

The document contains a Java program that checks if a given string is a palindrome using a method called 'palindrome'. It also defines a 'Cat' class with properties and methods related to a cat's characteristics and behaviors. The main method demonstrates the palindrome check and includes commented-out code for additional functionality.

Uploaded by

aashu.utir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

String&Class

The document contains a Java program that checks if a given string is a palindrome using a method called 'palindrome'. It also defines a 'Cat' class with properties and methods related to a cat's characteristics and behaviors. The main method demonstrates the palindrome check and includes commented-out code for additional functionality.

Uploaded by

aashu.utir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

*;

public class Main {


public static void main(String[] args) {
int num = 1000;
String str1 = new String("madam");

System.out.print(palindrome(str1));

// char arr [] = str1.toCharArray();


// char [] a1 = str1.toCharArray();

// for(int i = 0;i < str1.length()/2;i++){


// char temp = arr[i];
// arr[i] = arr[str1.length()-1-i];
// arr[str1.length()-1-i] = temp;
// }

// System.out.println(Arrays.toString(arr));

// System.out.print(Arrays.toString(arr));
// if(Arrays.toString(a1).equals(Arrays.toString(arr))){
// System.out.print("Palindrome");
// }
// else{
// System.out.print("Not Palindrome");
// }

// Cat c1 = new Cat ("munchkin",1000,'g');


// c1.name = "munchkin";
// c1.gender = 'g';
// c1.weight = 1000;
// c1.aboutMe();
// this
}
static boolean palindrome(String str){
int start = 0;
int end = str.length()-1;
while(start <= end){
if(str.charAt(start) == str.charAt(end)){
start++;
end--;
}
else{
return false;
}

}
return true;
}

class Cat{

//will be called only once


// when object is created
// name is same as class
// no return type
Cat(){

}
Cat(String name1, int weight1, char gender1){
this.name = name1;
this.gender = gender1;
this.weight = weight1;
}

//properties
String name ;
char gender;
int weight;

//functions
void meow(){
System.out.print("MEOWWWWWW");
}
void sit(){
System.out.print("I'm sitting");
}

void aboutMe(){
System.out.println(this.name);
System.out.println(this.gender);
System.out.println(this.weight);
}
}

You might also like