# Help me in solving LBJ21 problem Output are correct but fails after submitting

### My code

``````// Update the code below to solve this problem
import java.util.Scanner;

class Codechef
{
public static void main (String[] args)
{

for(int i=0; i<t; i++)
{

if(p%100>9){
System.out.println("-1");
}else if (p%100 ==0){
System.out.println(p/100);
}
else{
int a = p/100;
int b = p%10;
System.out.println(a+b);
}

}
}
}
``````

Learning course: Solve Programming problems using Java
Problem Link: CodeChef: Practical coding for everyone

@smparatwar
For p=10 it will print -1 but answer would be 10;

import java.util.Scanner;

class Codechef
{
public static void main (String[] args)
{

``````	int t = read.nextInt();
for(int i=0; i<t; i++)
{

if(p%100>9){
System.out.println("-1");
}
else if(p == 10){
System.out.println("10");

}

else if (p%100 ==0){
System.out.println(p/100);
}
else{
int a = p/100;
int b = p%10;
System.out.println(a+b);
}

}
}
``````

}

@smparatwar
Your code still print -1 for p=10 just run it .

// Update the code below to solve this problem
import java.util.Scanner;

class Codechef
{
public static void main (String[] args)
{

``````	int t = read.nextInt();
for(int i=0; i<t; i++)
{

if(p == 10){
System.out.println("10");
}
else if(p%100>9){
System.out.println("-1");
}

else if (p%100 ==0){
System.out.println(p/100);
}
else{
int a = p/100;
int b = p%10;
System.out.println(a+b);
}

}
}
``````

}
Now for 10 it is printing 10 but still wrong ?

@smparatwar
for p=1000 it should print 10 but your code will print -1;

import java.util.Scanner;

class Codechef
{
public static void main (String[] args)
{

``````	int t = read.nextInt();
for(int i=0; i<t; i++)
{

if(p%100 == 0 || p%100 < 9){
int a = p/100;
int b = p%10;
System.out.println(a+b);
}
else{
System.out.println(-1);
}

}
}
}
``````

@smparatwar
Here u go i have written in much simpler way hope u will get it.

``````// Update the code below to solve this problem
import java.util.Scanner;

class Codechef
{
public static void main (String[] args)
{

for(int i=0; i<t; i++)
{
int sc=p/100  +  p%100;
if(sc<=10)
System.out.println(sc);
else
System.out.println(-1);

}
}
}
``````

thank you bhaii

1 Like