I have tried this Snape problem and have been using JAVA, but NZEC Runtime error is being displayed while submitting the code. I am attaching my code, please let me know the mistake, I have been trying different methods but the result is same.
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
class Snape {
static ArrayList<Double> arr= new ArrayList<Double>(); //using for adding the input numbers into an array
static ArrayList<String> inputs = new ArrayList<String>(); // using this for the number of testcases
static void doThis(String s )
{
int l=0,m = 0;
StringTokenizer st = new StringTokenizer(s); //breaking the line e.g 10 15 using spaces in order to get 10 and 15 as different integers
while(st.hasMoreTokens())
{
try{
l = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
}
catch(Exception e)
{
return;
}
}
float z = l*l+m*m;
float d = m*m-l*l;
double max = Math.sqrt(z);
double min = Math.sqrt(d);
arr.add(min);
arr.add(max);
}
public static void main(String[] args) {
int test=0;
Scanner sc1 = new Scanner(System.in);
Scanner sc = new Scanner(System.in);
test = sc1.nextInt();
while(test>0)
{
inputs.add(sc.nextLine());
test--;
}
int noOfTest = inputs.size();
for(int i =0;i<noOfTest;i++)
doThis(inputs.get(i));
int n = arr.size();
boolean b = true;
int i =0;
while(i<n)
{
System.out.println(arr.get(i)+" "+arr.get(i+1));
i=i+2;
}
}
}