Run Time Error in program

M

mukesh tiwari

Hello all
I am trying to solve a problem on
http://uva.onlinejudge.org/index.ph...d=8&category=12&page=show_problem&problem=964
but i am consistently getting runtime error. I asked about this on
forum of respective site but no luck so i am asking here.
Thank you

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

//package uvaproblem_10023;
import java.io.*;
import java.math.BigInteger;

/**
*
* @author user
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
BufferedReader stdin= new BufferedReader(new
InputStreamReader(System.in));
String s_1=stdin.readLine();
// stdin.readLine();//for blank line
int n=Integer.parseInt(s_1);
boolean f=false;
for(int i=0;i<n;i++)
{
if(f)System.out.println();
f=true;
String s_2=stdin.readLine();
BigInteger x=new BigInteger(s_2);
BigInteger lo=BigInteger.ZERO,hi=x,mid;
while(lo.compareTo(hi)<0)
{
mid=(lo.add(hi)).divide(new BigInteger("2"));
BigInteger res=mid.pow(2);
if(res.compareTo(x)<0) lo=mid.add(new BigInteger("1"));
else hi=mid;

}
mid=(lo.add(hi)).divide(new BigInteger("2"));
//System.out.println(lo+" "+mid+" "+hi+" "+mid.pow(2));
System.out.println(mid);
}

}catch (NumberFormatException e){}
catch(IOException e){}
}

}
 
M

markspace

but i am consistently getting runtime error. I asked about this on

What is the error exactly? Please copy-and-paste the entire error
message, all lines of it.
}catch (NumberFormatException e){}
catch(IOException e){}


Also, get rid of these catch statements. You can't tell what is
happening if you don't print out these error messages. Don't catch
these, just throw them.
 
M

mukesh tiwari

What is the error exactly?  Please copy-and-paste the entire error
message, all lines of it.


Also, get rid of these catch statements.  You can't tell what is
happening if you don't print out these error messages.  Don't catch
these, just throw them.

Hi,

This is an automated response from UVa Online Judge.

Your submission with number 8290200 for the problem 10023 - Square
root has failed with verdict Runtime error.

This means that the execution of your program didn't finish properly.
Remember to always terminate your code with the exit code 0.

Best regards,

The UVa Online Judge team
This is the mail which i got from online judge.
 
M

mukesh tiwari

I am still getting run time error for throwing exceptions.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

//package uvaproblem_10023;
import java.io.*;
import java.math.BigInteger;

/**
*
* @author user
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws
NumberFormatException,IOException {
// try
{
BufferedReader stdin= new BufferedReader(new
InputStreamReader(System.in));
String s_1=stdin.readLine();
stdin.readLine();//for blank line
int n=Integer.parseInt(s_1);
boolean f=false;
for(int i=0;i<n;i++)
{
if(f)System.out.println();
f=true;
String s_2=stdin.readLine();
BigInteger x=new BigInteger(s_2);
BigInteger lo=BigInteger.ZERO,hi=x,mid;
while(lo.compareTo(hi)<0)
{
mid=(lo.add(hi)).divide(new BigInteger("2"));
BigInteger res=mid.pow(2);
if(res.compareTo(x)<0) lo=mid.add(new BigInteger("1"));
else hi=mid;

}
mid=(lo.add(hi)).divide(new BigInteger("2"));
//System.out.println(lo+" "+mid+" "+hi+" "+mid.pow(2));
System.out.println(mid);
}

}//catch (NumberFormatException e){}
//catch(IOException e){}
}

}
 
A

Arved Sandstrom

mukesh said:
Hi,

This is an automated response from UVa Online Judge.

Your submission with number 8290200 for the problem 10023 - Square
root has failed with verdict Runtime error.

This means that the execution of your program didn't finish properly.
Remember to always terminate your code with the exit code 0.

Best regards,

The UVa Online Judge team
This is the mail which i got from online judge.

As near as I can tell, from compiling your class and running it with
different arguments, it does seem to calculate the proper integer square
roots for N inputs, with the correct input and output format.

Give 'em what they're asking for; throw in a System.exit(0);

AHS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top