1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sergeinik [125]
3 years ago
14

Write an algorithm to print the minimum and maximum of an integer array. Your need to pass the array as a parameter. Since we ca

nnot return two values (in this case, minimum and maximum), just print them inside the method. You are allowed to use only one loop. i.e. you are not allowed to traverse the array twice. Note: You can write a Java method instead of pseudo-code but pseudo-code is preferred. Following is a template to start your pseudo code. MinMax(A) min
Computers and Technology
1 answer:
sammy [17]3 years ago
4 0

Answer:

See explaination

Explanation:

MinMax.java

import java.util.*;

public class MinMax

{

static void MinMax(int[] arr)

{

int Min=arr[0]; // initializinf min and max with 1st value of array

int Max=arr[0];

for(int i=0;i<arr.length;i++) // iterating loop only once

{

if(arr[i]>Max) // checking max value

{

Max=arr[i];

}

if(arr[i]<Min) // checking min value

{

Min=arr[i];

}

}

System.out.println("Min Number is "+Min); //printing min value

System.out.println("Max Number is "+Max); //printing max value

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter N value: "); // taking n value

int n=sc.nextInt();

int[] arr=new int[n];

System.out.println("Enter N elements:"); // taking n elements into array

for(int i=0;i<n;i++)

{

arr[i]=sc.nextInt(); // each element into the array

}

MinMax(arr); // calling MinMax() method.

}

}

You might be interested in
Write a function named repeat_words that takes two string parameters: 1. in_file: the name of an input file that exists before r
madam [21]

Answer:

#section 1

def repeat_words(firstFile, secondFile):

   infile_1=open(firstFile,'r')

   content1=infile_1.read()

   infile_1.close()

#section 2

   import string

   newContent=""

   for char in content1:

       newContent+=char.strip(string.punctuation)

   newContent=newContent.lower()

   newContent=newContent.split()

#section 3

   repeated_list=[]

   for word in newContent:

       if newContent.count(word)>1:

           repeated_list.append(word)

#section 4

   new_repeat_list=[]

   for item in repeated_list:

      while item not in new_repeat_list:

         new_repeat_list.append(item)

#section 5

   outfile=open(secondFile,'w')

   for repeat in new_repeat_list:

       outfile.write(repeat)

       outfile.write('\n')

   outfile.close()

   infile_2=open(secondFile,'r')

   content2=secondFile.read()

   infile_2.close()

   return content2

# section 6

in_file = 'aa.txt'

out_file = 'cpu.txt'

print(repeat_words(in_file, out_file))

Explanation:

#section 1

it defines a function that takes two arguments. It opens the first argument in the read mode and stores all it's content in a string variable "content1". finally the file is closed.

#section 2

In this section the string module is imported which allows for easy manipulation of string variables.

A new string variable is created that would store the already stripped file.

<em>strip(string.punctuation)  </em>strips every character of any leading or trialing punctuation.

<em>lower()  </em>converts string to lover case.

<em>split() </em>converts a string to an array of sub-string, i.e an array of words.

#section 3

This section collects all the words in the array and places them in a list.

#section 4

Utilizes a For and a While loop to ensure that no word repeats and stores it in a new list.

#section 5

Opens a new file and writes all the content into that new file and then closes the file.

re-opens the file, reads and returns the content of the file.

# section 6

This is added in order to test the function and print the result

I used your question to test the function and attached the result.

cheers!

8 0
3 years ago
Which describes the first step a crawler-based search engine uses to find information?
elena-14-01-66 [18.8K]
C is the correct answer to the problem
6 0
3 years ago
Read 2 more answers
If you implement a Wireless LAN (WLAN) to support connectivity for laptops in the Workstation Domain, which domain does WLAN fal
Mariana [72]

Answer:

Remote access domain

Explanation:

5 0
4 years ago
What is an optical drive used for?​
solong [7]

Optical Disc Drive (ODD) An optical disc drive (ODD)

for using CDs, DVDs, and Blu-ray discs to listen to music or watch a movie.

Most drives also allow you to write data to a disc, so you can create your own music CDs, video DVDs or even create of back-up copy of your important data files.

dell.com

4 0
2 years ago
Read 2 more answers
What are two examples of items in Outlook?
marta [7]

Answer:

I believe it would be button and tool bar

8 0
3 years ago
Other questions:
  • In the context of prototyping during the design phase of the systems development life cycle (SDLC), a _____ prototype shows user
    14·1 answer
  • In which of the following stages of the development process is a team MOST likely to interview a potential user of an app?
    6·1 answer
  • PLEASE HELP!!!!!!!!!!!
    15·2 answers
  • What acronym describes networked devices that contain microcomputers but are not thought of as computing devices, such as refrig
    9·1 answer
  • Find the number of ideal integers within the given segment [low,high] inclusive. An ideal number is a positive integer that has
    9·1 answer
  • Email, instant messaging and most web traffic go across the internet in the clear; that is, anyone who can capture that informat
    15·2 answers
  • An IP packet to be transmitted by Ethernet is 60 bytes long, including all its headers. If LLC is not in use, is padding needed
    15·1 answer
  • The <br> is an image at the top of the page that includes the title.
    14·1 answer
  • Label the parts of the plated salad.
    9·1 answer
  • Which is a guideline for conducting technical reviews?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!