Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  jwell.java
Language: JAVA
Code:



import java.io.DataInputStream;
import java.io.*;
import java.util.ArrayList;


public class Jwell
 {
    public static void main(String[] args)throws Exception {
       DataInputStream din=new DataInputStream(System.in);
     int count[]=new int[50];
        /*int i=1;
       char alph[]=new char[30];
for(char alp='a';alp<='z';alp++)
{

alp=(char)i;
int k=(int)alp;
System.out.println("alph["+alp+"]"+(int)i);
i++;
}*/
int d1=0,d2=0,s1=0,s2=0;

System.out.println("Enter the String:");
String str=din.readLine();

 ArrayList<String> s= new ArrayList();
    for ( int i = 1; i <= str.length(); i++) {
        char c=str.charAt(i);
        if(!s.contains(""+c))
        {
              s.add(""+str.charAt(i));

        }

    }
    for ( int i = 1; i <= s.size(); i++) {
        int c=0;
        for (int j = 1; j <= str.length(); j++) {

            if(s.get(i).equals(str.charAt(j)+"")){
     
                c++;
          count[i]=c;
            }
          else
          {
               count[i]=c;
          }
            
        }
        System.out.println("Occurance of "+ s.get(i) + " is "+ count[i]+ " times" );
     int p=s.size();
     if(p%2==0)
     {
     for(int k=1;k<=p;k++)
     {
          if(k%2 !=0)
          {
               d1=count[k]+d1;
          }
          else
          {
               s1=count[k]+s1;
          }
     }
     for(int k=p;k>0;k--)
     {
          if(k%2 ==0)
          {
               d2=count[k]+d2;
          }
          else
          {
               s2=count[k]+s2;
          }
     }
     }
     else
     {
     for(int k=1;k<=p;k++)
     {
          if(k%2 !=0)
          {
               d1=count[k]+d1;
          }
          else
          {
               s1=count[k]+s1;
          }
     }
     for(int k=p;k>0;k--)
     {
          if(k%2 !=0)
          {
               d2=count[k]+d2;
          }
          else
          {
               s2=count[k]+s2;
          }
     }
     }
     if((s1>d1)&&(s2>d2))
     {
          System.out.println("No");
     }
     else
     {
          System.out.println("Yes");
     }
          
     
   
      
}
    }
}
Comments: