repl.it
@Brawn/

Mastery Project #3C Code #1

Java

No description

fork
loading
Files
  • Main.java
  • PrimeNumber.java
Main.java
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
28
29
30
31
32
33
34
35
36
37
/*
Name:Allan Abraham
Purpose: This method shows the numbers of factors of 2 
in a given integer.
*/
public class Main {
	public static void main(String[] args) {
		int value = factor2(30);
		if (value != 1){
			boolean prime = PrimeNumber.ifPrime(value);
			System.out.print("Is the remaining number prime?\n"+prime);
		}
		else{
			System.out.print("The remaining number is 1");
		}
	}
	public static int factor2(int x) {
		int count = 0;
		int value = x;
		System.out.print(x+" = ");
		if(x % 2 == 0) {
			for(value = x; value % 2 == 0; count++) {
				value /= 2;
				System.out.print("2 * ");
			}
			System.out.println(value+"\n");
		}
		else {
			System.out.println(x+"\n");
		}
		return value;
	}
}



?