카테고리 없음

JAVA(메소드) - 두수를 나눗셈 연산으로 몫과 나머지를 구하는법

Meteora_ 2021. 1. 21. 14:44
728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class MainClass {
    public static void main(String[] args) {
 
int num01, num02;
        int result, tag[] = new int[1];
        
        num01 = 9;
        num02 = 4;    
        result = getResult(num01, num02, tag);
        
        System.out.println("몫:" + result + " 나머지:" + tag[0]);
    }    
 
    static int getResult(int n1, int n2, int t[]) {
        int r;
        r = n1 / n2;    // 몫
        t[0= n1 % n2;
        
        return r;
    }
cs