Results 1 to 3 of 3
  1. #1
    ajay.eeralla is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default does anyone know about the following error

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

    package sqrtbigint;
    import java.math.BigInteger;
    import java.util.Scanner;
    /**
    *
    * @author ajay
    */
    public class Sqrtbigint {

    /**
    * @param args the command line arguments
    */

    public static void main(String[] args)

    {
    // TODO code application logic here
    System.out.println("Enter a big integer");
    Scanner input=new Scanner(System.in);
    BigInteger n=new BigInteger(input.toString());

    BigInteger a = BigInteger.ONE;
    BigInteger b = new BigInteger(n.shiftRight(5).add(new BigInteger("8")).toString());
    while(b.compareTo(a) >= 0) {
    BigInteger mid = new BigInteger(a.add(b).shiftRight(1).toString());
    if(mid.multiply(mid).compareTo(n) > 0) b = mid.subtract(BigInteger.ONE);
    else a = mid.add(BigInteger.ONE);
    }
    System.out.println("sqrt of n= "+a.subtract(BigInteger.ONE).toString());



    }
    }
    Enter a big integer
    Exception in thread "main" java.lang.NumberFormatException: Illegal embedded sign character
    at java.math.BigInteger.<init>(BigInteger.java:308)
    at java.math.BigInteger.<init>(BigInteger.java:470)
    at sqrtbigint.Sqrtbigint.main(Sqrtbigint.java:25)
    Java Result: 1

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    10

    Default

    in order to read something with the class Scanner use

    Java Code:
    String s = input.nextLine();  
    BigInteger n=new BigInteger(s);
    Last edited by j2me64; 03-05-2011 at 10:54 AM.

  3. #3
    YAY
    YAY is offline Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    0

    Default

    And you should use [ CODE ][ /CODE ] when posting your code...

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •