Question

I need to come up with the pseudocode for a min and max value finder for...

I need to come up with the pseudocode for a min and max value finder for an array, uses recursion. first I started writing a java program to get a better understanding but it seams not to work properly. also Im having trouble calculating the time efficiency for the code.

public class Max_min {

    /**
     * @param args the command line arguments
     */
    static int Max;
    static int Min;
    static int index;
    static boolean b =true;
    static String answer;
  
    public static void main(String[] args) {
    int[] array={1,10,2,8,3,22,7};
    int val=0;
    System.out.println (find_min_max(array,val));
  
    }

public static String find_min_max(int a[],int x)
{
   index = Arrays.binarySearch(a, x);


   if (a[x] > Max)
        {
            Max = a[x];
        }
  
   if (a[x] <= Min)
        {
            Min = a[x];
        }

   {
        
   if(index < a.length)
   {
      find_min_max(a,(x+1));
   }
   return answer = "the max is "+ Max +" the min Value is "+Min;
}   

Homework Answers

Answer #1

public class Max_min {

/**
* @param args the command line arguments
*/
static int Max;
static int Min;
static int index;
static boolean b =true;
static String answer;
  
public static void main(String[] args) {
int[] array={1,10,2,8,3,22,7};
int val=0;
System.out.println (find_min_max(array,val));
  
}

public static String find_min_max(int a[],int x)
{
//index = Arrays.binarySearch(a, x);
if(x==0)
{
Max=Min = a[x];

}
if(x == a.length)
return answer = "the max is "+ Max +" the min Value is "+Min;
if (a[x] > Max)
{
Max = a[x];
}
  
if (a[x] <= Min)
{
Min = a[x];
}


  

find_min_max(a,(x+1));

return answer = "the max is "+ Max +" the min Value is "+Min;

}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
(This is for Java) For this I need to make a loop that will sum the...
(This is for Java) For this I need to make a loop that will sum the numbers from 3 to 22 public class Practice25 {    public static void main (String [] args) {            int sum = 0;           //The loop will go here      sum += i;     System.out.println ("Sum from 3 to 22 is: " + sum);    } }
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
So I would like to multiply a first digit by 2. I have to randomize either...
So I would like to multiply a first digit by 2. I have to randomize either 51-55 but multiply that first digit by 2 whichever the number may come out to be. I also need to keep the string. I need this to be in JAVA but so far Here is my code: import java.util.Random; public class Randoms {    public static void main(String[] args) {    Random rng = new Random();    String x;    int max = 55;...
import java.util.Scanner; public class InRange { private int min; private int max; public InRange(int initialMin, int...
import java.util.Scanner; public class InRange { private int min; private int max; public InRange(int initialMin, int initialMax) { min = initialMin; max = initialMax; } // You need to write two instance methods: // 1.) A method named inRange, which takes an int. // This returns true if the int is within the given range // (inclusive), else false. // // 2.) A method named outOfRange which takes an int. // This returns false if the int is within the...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
So I would like to multiply a first digit by 2. I have to randomize either...
So I would like to multiply a first digit by 2. I have to randomize either 51-55 but multiply that very first digit by 2 whichever the number may come out to be. I also need to keep the string. FOR EXMAPLE: Code generates 51, multiply 5 * 2 to get 10 1 or if it generates 54, multiply 5 * 2 to get 10 4 the 1 and the 4 always stay the same, only the 5 is getting...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
C Programming 1. Provide an equivalent of the java class in C class Example { public...
C Programming 1. Provide an equivalent of the java class in C class Example { public static int[][] question4(int n) { int[][] result = new int [n][n]; for(int i=1; i<=n; i+=1) for (int j=1; j<=n; j+=1) result[i][j] = (i*n)+j; return result; } public static void main(String[] args) { int[][] my array = question4(4); } } 2. Rewrite the following function using no loops, and only tail call recursion int min (int n, int[] input) { int i; int result; for...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT