Jump to content

Errors in program

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi, i am beginning to program with java and i get many erors so far. Here's my code which use java.lang.BigInteger class:

import java.lang.BigInteger;
import java.io.*;

class Calculator
{

public static void main(String[] args)
{

BigInteger number = new BigInteger();

number = getBigInteger();
System.out.println(number);

}

static BigInteger getBigInteger()
{

String line;
DataInputStream input = new DataInputStream(System.in);

line = input.readLine();

BigInteger number = new BigInteger(line);

return number;

}

}

1. First of, why in the first line i always get error: the import of java.lang.BigInteger cannot be resolved?
When i type import java.lang.* instead of it, it's ok, but get error "BigInteger cannot be resolved to a type" in that line: BigInteger number = new BigInteger();

#2
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
1) It's java.math.BigInteger
2) BigInteger doesn't have an empty constructor: "new BigInteger();"
3) DataInputStream doesn't seem like a right thing to use here. The method you are accessing is deprecated(Not recommended anymore).

fixed it for you.

import java.math.BigInteger;
import java.io.*;

public class Calculator
{

    public static void main(String[] args) throws IOException
    {

        BigInteger number;
        number = getBigInteger();
        System.out.println(number);

    }

    static BigInteger getBigInteger() throws IOException
    {
        String line;
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
                        
        line = input.readLine();
        return new BigInteger(line);
    }

}