Java - Scanner problem

Hi, I know this is not related to C++ but still. Why do I get an error when I use one scanner to get an integer then to get a string from the console? If I use two different scanner then it doesn't give any error.

This is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.math.BigInteger;
import java.util.Scanner;

class Test
{
    public static void main(String[] args)
    {
        BigInteger[] muls = new BigInteger[1000];
        Scanner gets = new Scanner(System.in);

        int n = gets.nextInt();
        
        for(int i = 1; i<=n; i++)
        {
            String input = gets.nextLine();
            String[] input_s = input.split(" ");
            BigInteger x = new BigInteger(input_s[0]);
            BigInteger y = new BigInteger(input_s[1]);
            muls[i-1] = x.multiply(y);
        }
        
        for(int j = 0; j<n; j++)
        {
            System.out.println(muls[j]);
        }
    }
}
Dont you have to use a string conversion?
closed account (Dy7SLyTq)
why are you posting here? if i remember my java correctly its usually better to just get raw data and use the parse methods

edit: and why is this in the windows page?
Last edited on
Put this in the lounge... you'd get a better chance of getting it answered there.
Topic archived. No new replies allowed.