Want this question answered?
public class PrimeNumberPrint {/*** @param args*/public static voidmain(String[] args) {// TODO Auto-generated method stubfor(int i =2; i < 10; i++) {System.out.println(i + " is prime is " + isPrime(i));}}public static booleanisPrime(int n) {int x = n;for(int i=2; i
Implement these methods: public static int smallest(int[] arr) { int small = arr[0]; for(int i = 1; i < arr.size(); i++) if(arr[i] < small) small = arr[i]; return small; } public static int largest(int[] arr) { int large = arr[0]; for(int i = 1; i < arr.size(); i++) if(arr[i] > large) large = arr[i]; return large; }
package javaapplication1; public class JavaApplication1 { public static boolean is_prime(int val){ if (val
Implement this method: public static boolean isDivisible(int a, int b) { if(a % b == 0) { return true; } else { return false; } }
public static int fib(int n) {return fib(n-1) + fib(n-2);}
class MyClass { // Declare a static method to return the square of a number. public static int getSquare(final int n) { return n*n; } public static void main(String[] args) { // Call the static method to find 1522 System.out.println( MyClass.getSquare(152) ); } }
public class Primes { public static void main(String[] args) { for(int i = 2; i < 100; i++) { if(isPrime(i)) { System.out.println(i); } } } public static boolean isPrime(int n) { if(n 0) return false; } return true; } } }
public class PrimeNumberPrint {/*** @param args*/public static voidmain(String[] args) {// TODO Auto-generated method stubfor(int i =2; i < 10; i++) {System.out.println(i + " is prime is " + isPrime(i));}}public static booleanisPrime(int n) {int x = n;for(int i=2; i
// Returns the index of n in ns or -1 if not found. public static final int linearSearch(final int n, final int[] ns) { for(int i = 0; i < ns.length; ++i) { // If found, return the index if(ns[i] == n) { return i; } } return -1; }
Implement these methods: public static int smallest(int[] arr) { int small = arr[0]; for(int i = 1; i < arr.size(); i++) if(arr[i] < small) small = arr[i]; return small; } public static int largest(int[] arr) { int large = arr[0]; for(int i = 1; i < arr.size(); i++) if(arr[i] > large) large = arr[i]; return large; }
package javaapplication1; public class JavaApplication1 { public static boolean is_prime(int val){ if (val
Implement this method: public static boolean isDivisible(int a, int b) { if(a % b == 0) { return true; } else { return false; } }
These are the two functions you need: public static int lcm(int i1, int i2) { return (i1*i2/gcd(i1,i2)); } public static int gcd(int i1, int i2) { // using Euclid's algorithm int a=i1, b=i2, temp; while (b!=0) { temp=b; b=a%temp; a=temp; } return a; }
public static int fib(int n) {return fib(n-1) + fib(n-2);}
public class Main{ public static void main(String[] args){ System.out.println("the factorial of 5 is: " + getFactorial(5)); } public static int getFactorial(int num){ return num + getFactorial(num-1); } }
class maximum{public static void main(string...args){System.out.println(max(new int[]{5,3,6,2,4,61}));}static int max(int[]a){int max=0;for(int i=0;imax)max=a[i];}return max;}}
public class FindLeastAndGreatest { public static void main(String[] args) { // number can't be equal with each other int a = 7; int b = 7; int c = 6; System.out.println(least(a,b,c)); System.out.println(greatest(a,b,c)); } public static int least(int a, int b, int c) { int least = 0; if(a < b && a < c) { least = a; } else if(b < a && b < c) { least = b; } else { least = c;} return least; } public static int greatest(int a, int b, int c) { int greatest = 0; if(a > b && a > c) { greatest = a; } else if(b > a && b > c) { greatest = b; } else { greatest = c;} return greatest; } }