/* Find duplicate string count in n number of strings */
import java.util.Scanner;
public
StringDuplicate(){
Scanner s=new
Scanner(System.in);
System.out.println("Enter number of Strings :");
int n=s.nextInt();
int flag,ctr;
String[] str=new
String[n];
System.out.println("Enter "+n+" strings");
str[i]=s.next();
System.out.println("\n");
for(int
i=0;i<n;i++){
ctr=1;
flag=0;
/*
check */
for(int k=0;k<i;k++)
{
if(str[k].equals(str[i]))
{
flag=1;
break;
}
}
if(flag==0) {
for(int
j=i+1;j<n;j++){
if(str[i].equals(str[j]))
ctr++;
}
if(ctr>1)
System.out.println(""+str[i]+" = "+ctr);
}
}
}
}
class eXecute{
public static void
main(String[] args){
StringDuplicate
obj=new StringDuplicate();
}
}
/* print true if array spli sum equals
ex:- 2+20 is equals to 4+5+13 */
/* print true if array spli sum equals
ex:- 2+20 is equals to 4+5+13 */
public class MyClass {
public static void main(String args[]) {
int no[]={2,20,4,5,13};
int lsum=0,rsum=0;
int k;
for(int i=0;i<no.length;i++)
{
lsum=rsum=0;
for(k=0;k<=i;k++)
lsum+=no[k];
for(int j=i+1;j<no.length;j++)
{
rsum+=no[j];
}
System.out.println(lsum+"\t"+ rsum+" pos ");
if(lsum==rsum)
{
System.out.println("true "+ k);
}
}
}
}
No comments:
Post a Comment