import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
class DhapuandHammingDistance {
public static void main(String arg[])throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr=new PrintWriter(System.out,true);
int t,c,i,l1,l2;
char c1[],c2[];
t=Integer.parseInt(br.readLine());
while(t-->0){
c1=br.readLine().toCharArray();
c2=br.readLine().toCharArray();
l1=c1.length;l2=c2.length;c=0;
if(l1!=l2)
pr.println(-1);
else{
for(i=0;i<l1;i++){
if(c1[i]!=c2[i])
c++;
}
pr.println(c);
}}}}
Please give more information about the problem which you are attempting. Format your code correctly or give link, it is too clumsy to read.
Read how to ask a question here.
You are converting string to character array simultaneously when you are taking input this is leading to runtime error.
Read [here][1] for how to convert string to character array in java.
Correction:
-
take string as input first,
-
then convert it to character array
[Here][2] is your corrected code.
P.S. - You still need to check ur logic for the problem.
[1]: http://stackoverflow.com/questions/10006165/converting-string-to-character-array-in-java
[2]: http://ideone.com/tm0TUo
i am getting runtime error on codechef not on my eclipse
also getting runtime error in this there is no string
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.util.Arrays;
class ComplementaryCouples {
public static void main(String arg[])throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr=new PrintWriter(System.out,true);
int n,i,j,l,h,m,c=0;
long k,a[],num;
n=Integer.parseInt(br.readLine());
k=Long.parseLong(br.readLine());
a=new long[n];
for(i=0;i<n;i++)
a[i]=Integer.parseInt(br.readLine());
Arrays.sort(a);
for(j=0;j<n;j++){
num=k-a[j];
l=j+1;h=a.length-1;
while(l<=h){
m=(l+h)/2;
if(a[m]==num){
c=1;break;
}
else if(a[m]<num)
l=m+1;
else
h=m-1;
}
}
if(c==1)
pr.println("YES");
else
pr.println("NO");
}}
Which problem you are attempting to solve ??