Skip to main content

Write a program to check whether two strings are anagram or not.


import java.util.*;
public class anagrams {
    public static void main(String[] args) {
        int count=0,i;
        Scanner sc= new Scanner(System.in);
        System.out.println("enter first string");
        String a=sc.nextLine();
        System.out.println("enter second string");
        String b=sc.nextLine();
        a=a.toLowerCase();
        b=b.toLowerCase();
        char a1[]=a.toCharArray();
        char a2[]=b.toCharArray();
        Arrays.sort(a1);
        Arrays.sort(a2);
        if(a1.length!=a2.length)
            count++;
        if(count==0)
        for(i=0;i<a1.length;i++)
            if(a1[i]!=a2[i])

                count++;

        if(count==0)
            System.out.println("anagrams");
        else
            System.out.println("not anagrams");
    }
}

Comments

Popular posts from this blog

Implemet Stack in python

  class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( data ) def push ( self , data ): self . stack . append ( data ) def pop ( self ): popped_elemnt = self . stack . pop () def show ( self ): for i in self . stack : print ( i ) s = Stack ( 45 ) s . push ( 23 ) s . push ( 29 ) s . push ( 695 ) s . show () s . pop () s . show ()

wap in c to implement newton's forward interpolation formula.

Question -- using newton forward interpolation formula , find the area of a circle of diameter 82 metre                                from the given table of diameter and area of circle. Diameter(metre)      80          85           90          95            100 Area(metre^2)      5026        5674      6362     7088         7854 code to solve the above question. #include<stdio.h> #include<math.h> main() { int i,j,a=0,n; float x[10],fx[10],delfx[10],result=0,point,f,h,p,fact=1.000; printf("\nthe point at which u want to calculate the value\n"); scanf("%f",&point); printf("\nenter the no of elements in x\n"); scanf("%d",&n); printf("enter the elements of x\n"); for(i=0;i<n;i++) scanf("%f",&x[i]); h=fabs(x[0]-x[1]); p=(point-x[0])/h; printf("\nthe value of p is %f\n",p); printf("enter the elements of f(x)\n"); for(i=0;i<n;i++) scanf("%f",

Bold image

Launched in india.