2016-10-20 2 views
-2

BigInteger 변수를 정수 변수로 나눌 때 몫의 값을 인쇄하려하지만 컴파일러가 "스레드"의 주 예외 "java.lang.RuntimeException : Uncompilable source code - 이진 연산자의 잘못된 피연산자 유형/'첫 번째 유형 : java.math.BigInteger의 두 번째 유형 : INT "Bigayer와 int의 두 변수를 나누는 동안 몫의 값을 저장하는 방법은 무엇입니까?

public static void main(String[] args) { 
    String s; 
    BigInteger n, repeat, remainder; 
    Scanner in=new Scanner(System.in); 
    s=in.nextLine(); 
    n=in.nextBigInteger(); 
    repeat=n/s.length(); 
    System.out.println(repeat); 
} 
+0

큰 INT에 INT를 전송하고 큰 INT 연산을 수행하고 출력 큰 INT 메소드 결과를 사용해서 큰 INT에 저장한다. –

+0

여기에 코드를 붙여 넣을 수 있습니까? –

+0

public static void main (String [] args) { 문자열 s; BigInteger n, repeat, remainder; 스캐너 in = 새 스캐너 (System.in); s = in.nextLine(); n = in.nextBigInteger(); repeat = n/s.length(); System.out.println (반복); } –

답변

1
  1. 이 BigInteger를로 INT 변환합니다.
  2. BigInteger.divide 메서드를 사용하여 작업을 수행합니다. (/ 피연산자 기본 유형으로 만 작동한다.)

    import java.math.BigInteger; 
    import java.util.Scanner; 
    
    public class ModuloTest { 
    
        public static void main(String[] args) { 
         String s; 
         BigInteger n, repeat, remainder; 
         Scanner in = new Scanner(System.in); 
         s = in.nextLine(); 
         n = in.nextBigInteger(); 
         BigInteger length = BigInteger.valueOf(s.length()); 
         repeat = n.divide(length); 
    
         System.out.println(repeat); 
        } 
    
    }