Tugas Algoritma Dan Pemrogaman: A. Saverina A. 076
Tugas Algoritma Dan Pemrogaman: A. Saverina A. 076
A. Saverina A.
076
package test.pass.by.value;
public class TestPassByValue {
/*main method*/
public static void main(String[] args) {
// Declare and initialize variables
int num1 = 1;
int num2 = 2;
System.out.println("Before invoking the swap method, num1 is " + num1 + " and
num2 is " + num2);
// Invoke the swap method to attempt to swap two variables
swap(num1, num2);
System.out.println("After invoking the swap method, num1 is " + num1 + " and
num2 is " + num2);
}
// Swap n1 with n2
int temp = n1;
n1 = n2;
n2 = temp;
System.out.println("\t\tAfter swapping, n1 is " + n1 + " and n2 is " + n2);
2. Listing 5.6
package greatest.common.divisor.method;
import java.util.Scanner;
public class GreatestCommonDivisorMethod {
System.out.println("The greatest common divisor for " + n1 + " and " + n2 + " is "+
gcd(n1, n2));
}
3. Listing 5.7
package prime.number.method;
public class PrimeNumberMethod {