My issue
string is out box please somebody help where i am wrong
My code
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T>0){
int N=sc.nextInt();
int i=0;
String s=sc.nextLine();
while(i<N){
if(s.charAt(i)==0 && s.charAt(i+1)==0){
System.out.print("A");
}
else if(s.charAt(i)==0 && s.charAt(i+1)==1){
System.out.print("T");
}
else if(s.charAt(i)==1 && s.charAt(i+1)==0){
System.out.print("C");
}
else if(s.charAt(i)==1 && s.charAt(i+1)==1){
System.out.print("G");
}
i=i+2;
}
T--;}
}
}
Learning course: Strings using Java
Problem Link: CodeChef: Practical coding for everyone
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t;
t=sc.nextInt();
sc.nextLine();
while(t>0){
int N=sc.nextInt();
sc.nextLine();
String s=sc.nextLine();
for (int i = 0; i < N ; i += 2) {
int m = (s.charAt(i) - '0') * 10 + (s.charAt(i + 1) - '0');
if (m == 0) {
System.out.print("A");
} else if (m == 1) {
System.out.print("T");
} else if (m == 10) {
System.out.print("C");
} else {
System.out.print("G");
}
}
System.out.println();
t=t-1;
}
}
}
this code will work you can compare.
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
sc.nextLine();
while(T>0){
int N=sc.nextInt();
sc.nextLine();
int i=0;
String s=sc.nextLine();
while(i<N){
if((s.charAt(i)-‘0’)==0 && (s.charAt(i+1)-‘0’)==0){
System.out.print(“A”);
}
else if((s.charAt(i)-‘0’)==0 && (s.charAt(i+1)-‘0’)==1){
System.out.print(“T”);
}
else if((s.charAt(i)-‘0’)==1 && (s.charAt(i+1)-‘0’)==0){
System.out.print(“C”);
}
else if((s.charAt(i)-‘0’)==1 && (s.charAt(i+1)-‘0’)==1){
System.out.print(“G”);
}
i=i+2;
}
System.out.println();
T–;}
}
} this is you code.