Closed ErSKS closed 7 years ago
package bunkerexample;
/*
@author m-lan */ public class BunkerExample {
/**
public static boolean isBunker(int[] arr) { byte f = 0; boolean result = true; PrimeCheck pcheck = new PrimeCheck(); int arlen = arr.length; if (arlen == 0) { result = false; } else { for (int i = 0; i < arlen; i++) { if (pcheck.isPrime(arr[i]) == true) { f = 1; } else { result = false; } } if (f == 1) { for (int i = 0; i < arr.length; i++) { if (arr[i] == 1) { result = true;
} else {
result = false;
}
}
}
}
return result;
}
} Class PrimeCheck package bunkerexample;
/*
@author m-lan */ public class PrimeCheck {
boolean isPrime(int n) { if (n < 2) { return false; } int countFactor = 0; boolean result = true; for (int i = 1; i < n && result == true; i++) { if (n % i == 0) { countFactor++;
}
if (countFactor > 1) {
return false;
}
}
return result;
}
}
Output
/*
/*
@author nissus */ public class Day132 {
/**
@param args the command line arguments */ public static void main(String[] args) { System.out.println("Bunker Array - contains the value 1 if and only if it contains a prime number"); System.out.println("{7, 6, 10, 1} true:" + isBunker(new int[]{7, 6, 10, 1})); System.out.println("{7, 6, 10} false:" + isBunker(new int[]{7, 6, 10})); System.out.println("{6, 10, 1} false:" + isBunker(new int[]{6, 10, 1})); System.out.println("{3, 7, 1, 8, 1} true:" + isBunker(new int[]{3, 7, 1, 8, 1})); System.out.println("{7, 6, 10, 9, 5, 0, 1} true:" + isBunker(new int[]{7, 6, 10, 9, 5, 0, 1})); System.out.println("{}false:"+isBunker(new int[]{})); System.out.println("{7, 10} false:" + isBunker(new int[]{7, 10})); System.out.println("{6, 1} false:" + isBunker(new int[]{6, 1})); System.out.println("{3, 1, 1} true:" + isBunker(new int[]{3, 1, 1})); }
// TODO code application logic here
static boolean isBunker(int[] a) { int prime=0,one=0; int len=a.length; for(int i=0;i<len;i++) { if (isPrime(i)==true){ prime++; } } if (prime>1){ for (int i=0;i<len;i++){ if (a[i]==1) { one++; } } if (one>=1) return true; else return false; } return false; } static boolean isPrime(int n){ if(n<2){ return false;} int countfactor=0; boolean result=true; for(int i=1;i<n && result==true;i++){ if(n%i==0) { countfactor++; } if(countfactor>1) { return false; } } return result; } }
/*
/*
@author DELL */ public class Bunker {
/**
@param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here System.out.println("Bunker Array - contains the value 1 if and only if it contains a prime number"); System.out.println("{7, 6, 10, 1} true:" + isBunker(new int[]{7, 6, 10, 1})); System.out.println("{7, 6, 10} false:" + isBunker(new int[]{7, 6, 10})); System.out.println("{6, 10, 1} false:" + isBunker(new int[]{6, 10, 1})); System.out.println("{3, 7, 1, 8, 1} true:" + isBunker(new int[]{3, 7, 1, 8, 1})); System.out.println("{7, 6, 10, 9, 5, 0, 1} true:" + isBunker(new int[]{7, 6, 10, 9, 5, 0, 1})); System.out.println("{} false:" + isBunker(new int[]{}));
System.out.println("{7, 10} false:" + isBunker(new int[]{7, 10})); System.out.println("{6, 1} false:" + isBunker(new int[]{6, 1})); System.out.println("{3, 1, 1} true:" + isBunker(new int[]{3, 1, 1})); }
static boolean isBunker(int ar[]) { int a[] = new int[ar.length]; boolean c = false; boolean b = false;
for (int i = 0; i < ar.length; i++) {
a[i] = ar[i];
if (PrimeCheck(a[i]) == true) {
b = true;
break;
} else {
b = false;
}
}
for (int i = 0; i < ar.length; i++) {
a[i] = ar[i];
if (ar[i] == 1) {
c = true;
break;
} else {
c = false;
}
}
if (b == true && c == true) {
return true;
} else {
return false;
}
}
static public boolean PrimeCheck(int a) { int p = a, c, d = 0; for (int i = 1; i <= p; i++) { c = p % i; if (c == 0) { d++; } } if (d > 2) { return false; } else { return true; } } }
OUTPUT
package bunkerarray39;
/*
@author jagdish */ public class BunkerArray39 {
/**
@param args the command line arguments */ public static void main(String[] args) { System.out.println("Bunker Array - contains the value 1 if and only if it contains a prime number"); System.out.println("{7, 6, 10, 1} true:" + isBunker(new int[]{7, 6, 10, 1})); System.out.println("{7, 6, 10} false:" + isBunker(new int[]{7, 6, 10})); System.out.println("{6, 10, 1} false:" + isBunker(new int[]{6, 10, 1})); System.out.println("{3, 7, 1, 8, 1} true:" + isBunker(new int[]{3, 7, 1, 8, 1})); System.out.println("{7, 6, 10, 9, 5, 0, 1} true:" + isBunker(new int[]{7, 6, 10, 9, 5, 0, 1}));
System.out.println("{7, 10} false:" + isBunker(new int[]{7, 10})); System.out.println("{6, 1} false:" + isBunker(new int[]{6, 1})); System.out.println("{3, 1, 1} true:" + isBunker(new int[]{3, 1, 1})); }
static boolean isBunker(int[] a) { boolean result = false; int count1 = 0, count=0, countPrime =0; for (int i : a) { if(i == 1) count1++; for(int j = 1 ; j<=i; j++){ if(i%j==0) count++; } if(count==2) countPrime++; }
if(count1 >=1 && countPrime>=1) result = true;
// System.out.print("count1 = "+ count1); // System.out.println("countPrime="+ countPrime); return result; }
}
/*
/*
@author LORDsajan */ public class BunkArray {
public static boolean isBunker(int a[]) { boolean result = false; int c = 0, p = 0; for (int i = 0; i < a.length; i++) { int j = a[i]; boolean res = primeChecker(j); if (a[i] == 1) { c++; } if (res == true) { p++; } if (c != 0 && p > 1) { result = true; } } return result; }
public static boolean primeChecker(int n) { int i; if (n == 1) { return true; } else { for (i = 2; i < n; i++) { if (n % i == 0) { return false; } } return i == n; } }
public static void main(String[] args) { System.out.println("Bunker Array - contains the value 1 if and only if it contains a prime number"); System.out.println("{7, 6, 10, 1} true:" + isBunker(new int[]{7, 6, 10, 1})); System.out.println("{7, 6, 10} false:" + isBunker(new int[]{7, 6, 10})); System.out.println("{6, 10, 1} false:" + isBunker(new int[]{6, 10, 1})); System.out.println("{3, 7, 1, 8, 1} true:" + isBunker(new int[]{3, 7, 1, 8, 1})); System.out.println("{7, 6, 10, 9, 5, 0, 1} true:" + isBunker(new int[]{7, 6, 10, 9, 5, 0, 1})); System.out.println("{7, 10} false:" + isBunker(new int[]{7, 10})); System.out.println("{6, 1} false:" + isBunker(new int[]{6, 1})); System.out.println("{3, 1, 1} true:" + isBunker(new int[]{3, 1, 1})); } }
/*
/*
@author Dragon15423 */ public class TestingBunker {
/**
public static boolean isBunker(int n[]) { boolean result = false; int c = 0, o = 0; for (int i = 0; i < n.length; i++) {
if (isPrime(n[i]) == true && n[i] != 1) {
c++;
}
if (n[i] == 1) {
o++;
}
if (c > 0 && o > 0) {
result = true;
break;
}
}
return result;
}
public static boolean isPrime(int num) { boolean result = true;
if (num < 0) {
result = false;
} else {
for (int i = 2; i < num; i++) {
if (num % i == 0) {
result = false;
break;
}
}
}
return result;
}
}
/*
/*
@author Dell */ public class BunkerArray {
/**
@param args the command line arguments */ static boolean isBunker(int a[]) { boolean result = false, b = false;
int ar[] = new int[a.length]; for (int i = 0; i < a.length; i++) { ar[i] = a[i]; if (isprime(ar[i]) == true) { b = true; break; } }
for (int i = 0; i < a.length; i++) { if (a[i] == 1) { result = true; break; }
} if (b == true && result == true) { return true; } else { return false; } }
static boolean isprime(int a) { int count = 0; for (int i = 1; i <= a; i++) {
if (a % i == 0) {
count = count + 1;
}
}
if (count == 2) {
return true;
} else {
return false;
}
}
public static void main(String[] args) { // TODO code application logic here System.out.println("{7,6,5,1}true:" + isBunker(new int[]{7, 5, 1})); System.out.println("{3,1,1}true:" + isBunker(new int[]{3, 1, 1})); System.out.println("{7,10}false:" + isBunker(new int[]{7, 10})); System.out.println("{6,1}false:" + isBunker(new int[]{6, 1})); System.out.println("{}false:" + isBunker(new int[]{})); System.out.println("{1,8,7,6}true:" + isBunker(new int[]{1, 8, 7, 6})); }
}
/*
/*
@author Anish */ public class BunkerArray {
public static boolean isBunker(int a[]) { boolean p = false, o = false; for (int b : a) { if (isPrime(b)) { p = true; } if (b == 1) { o = true; } if (p && o) { return true; } } return false; }
public static boolean isPrime(int n) { if (n < 2) { return false; } for (int i = 2; i < n / 2; i++) { if (n % i == 0) { return false; } } return true; }
/**
}
Develop a static method static boolean isBunker(int[] a) {} for the following PSVM