Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Hw2 {
- //make input available
- static Scanner mfive = new Scanner(System.in);
- static int num = mfive.nextInt();
- static int[] aprime = xFactor(Math.abs(num));
- public static void main(String[] args){
- if(num<0){
- System.out.println("no negatives");
- num=mfive.nextInt();
- }
- if (fCheck(aprime)==false){
- System.out.println("not ugly numder");
- }else{
- System.out.println("ugly number");
- }
- for(int i=0; i<aprime.length; i++){
- System.out.print(aprime[i]+", ");
- }
- }
- //identify 2, 3, and 5 factors
- public static boolean fCheck(int[] a){
- for(int i=0; i <a.length; i++){
- if(a[i] ==1 || a[i]==2 || a[i] ==3 || a[i] ==5){
- return true;
- }
- }
- return false;
- }
- //array for factors
- public static int[] xFactor(int n)
- {
- ArrayList<Integer> f = new ArrayList<Integer>();
- f.add(1);
- for (int a = 2; n>1;){
- if (n%a==0)
- {
- f.add(a);
- n/=a;
- }
- else{
- a++;
- }
- }
- int[] out = new int[f.size()];
- for (int a = 0; a < out.length; a++)
- out[a] = f.get(a);
- return out;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement