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
I need to get the Min and Max value of an array when a user inputs...
I need to get the Min and Max value of an array when a user inputs values into the array. problem is, my Max value is right but my min value is ALWAYS 0. how do i fix this? any help please!!! _________________________________________________________________________________________________ import java.util.Scanner; public class ArrayMenu{ static int count; static Scanner kb = new Scanner(System.in);             public static void main(){ int item=0; int[] numArray=new int[100]; count=0;       while (item !=8){ menu(); item = kb.nextInt();...
[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...
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) {...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
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...
//please debug program // need Scanner output import java.util.Scanner; // Display every character between Unicode 65...
//please debug program // need Scanner output import java.util.Scanner; // Display every character between Unicode 65 and 122 // Start new line after 20 characters public class DebugSix2 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); char letter; int a; final int MIN = 65; final int MAX = 122; final int NUMPERLINE = 200; final int STOPLINE1 = 0; final int STOPLINE2 = STOPLINE1 + NUMPERLINE; for(a = MIN; a <= MAX; a++) { letter...
(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);    } }
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...
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;...
When I run the main method with the test case, it returns the list backwards. How...
When I run the main method with the test case, it returns the list backwards. How can I fix it so that it gives me all 6 correct actions? My guess is that the problem is in the getAction() function. public class StringDoublyLinkedList { /** * A private class to represent a link in the linked list. */ private class Node { String value; Node next; Node prev; Node(String value) { this.value = value; this.next = null; this.prev = null;...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT