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
lilavasa [31]
4 years ago
11

Write a Java class with the following methods: getArray(int numStrings) is an instance method that takes command line input (use

a Scanner's nextLine() method) to create an array of Strings whose length is numStrings and returns a reference to the array. getArray() does not print anything! getLongestString(String[] sArray) is an instance method that returns a reference to the longest String in sArray. getLongestString() does not print anything! main() creates an instance of the class and uses it to call getArray() with the argument 5, keeping a reference to the return value, then sends the array to getLongestString(), and prints the result

Computers and Technology
1 answer:
mezya [45]4 years ago
4 0

Answer:

Follows are the code to this question:

import java.util.*;//import packae for user-input  

public class Main//defining a class Main

{

public String[] getArray(int numString)//defining a method getArray

{

String[] name=new String[numString];//defining array of String values

Scanner in = new Scanner(System.in);// creating scanner class object for input values from user-end

for(int i=0;i<numString;i++)//defining for loop for input multiple values

{

System.out.print("Enter String Value :");//print message

name[i]=in.nextLine();//input values

}

return name;//return array values

}

public String getLongestString(String[] sArray)//defining a method getLongestString

{

int m=0,mi=0; //defining integer variables

for(int i=0;i<sArray.length;i++)//defining for loop for check the longest value in array

{

if(m<sArray[i].length())//defining if block that checks m varaible value greater then sArray length  

{

m=sArray[i].length();//use m to hold sArray length

mi=i;//use max_index to hold i that is loop value

}

}

return sArray[mi];//return Longest value

}

public static void main(String[] args)//defining main method

{

Main s=new Main();//Creating object of main class    

String[] n;//defining string variable n  

n=s.getArray(5);//use n varaible to call getArray method and store its value

System.out.println("Longest value is: "+s.getLongestString(n));//use print method to call getLongestString method

}

}

Output:

please find attached file.

Explanation:

In the given java program code, inside the main class two method that is "getArray and getLongestString", is defined, in which the "getArray" method uses an integer variable in its parameter and inside the method, an array is defined that use a  scanner class for input array value.

  • In the "getLongestString" pass as a parameter and inside the method, two integer variable "m and mi" is defined that use in the loop to return the longest string value.
  • In the class main method is to define that creates a class object and call the above method and use the print method to return its value.  

You might be interested in
In a paragraph, describe in detail a practical real-world example of where you would implement a singly-linked list and why a si
frosja888 [35]

Answer:

travel

Explanation:

One real world example of a singly-linked list would be travel. Imagine that you want to take a trip to your nearest neighbor state. To do so you would need to take a 2 buses and a train, but you can't just take any or in any order you wish. You first need to take the first bus at your current location, get off at the train station, take that train to the final stop, get off and take the bus to the final destination. Meaning there is a sequence of connected events that you must follow in order to get to your destination and the same opposite sequence of events to get back. This is exactly like a singly-linked list.

3 0
3 years ago
The commands available from a menu may change as a result of a user's actions.
kiruha [24]
True. Say we have 3 options and the three options are: create a text file, move the text file and rename the text file. But the user wants to delete the file. But he can't because there is no option for deletion. So his best option is to move the text file to another folder. To at least get it out of the way.
8 0
3 years ago
What is the tool used to see the movement of storm clouds
adoni [48]
Sometimes scientists use weather satellites.
8 0
3 years ago
Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB, and 125 KB (in order). The memory allocation algorithm th
Makovka662 [10]

Answer:

The memory allocation algorithm that is used to place the processes given is the <u>First Fit Algorithm </u>

Explanation:

The First Fit Management Algorithm works by ensuring that the pointer keeps track of all the free spaces in the memory and accepts and executes all instructions to allocate a memory block to the coming process as long as it is big enough to hold the size of the process.

For example, the First Fit algorithm will allocate the processes in the first block that fits (that is, if it can fit the memory bock in the queue, then the process will be store)

It will work as follows (recall that the memory partitions are in order and must remain so):

A) 115 KB is stored in 300KB block, leaving the following free spaces (185KB, 600KB, 350KB, 200KB, 750KB, 125KB), next

B) 500 KB is store in a 600KB block leaving the following free spaces (185 KB, 100  KB, 350 KB, 200 KB, 750 KB, 125 KB), next  

C) 358 KB is stored in 750KB block, leaving the following free spaces (185KB, 100KB, 350KB, 200KB, 392KB, 125KB)  next

D) 200 KB is stored in 350KB block, leaving the following free spaces (185 KB, 100 KB, 150KB, 200KB, 392KB, 125KB)  next

E) 375KB is stored in 392KB block leaving (185KB, 100KB, 150KB,  200KB, 17KB, 125KB)

One of the demerits of this Algorithm is that, as shown above, memory is not maximized. It however is one of the easiest algorithms amongst all the other memory allocation processes.

Cheers

5 0
3 years ago
A computer network is _____.
ad-work [718]

Answer:

a

Explanation:

a group of people who help you solve any technical issues

3 0
3 years ago
Other questions:
  • Enter a formula in cell b7 to calculate the average value of cells b2:b6
    13·1 answer
  • Software development team leaders need (blank)<br> skills to excel in directing their teams.
    7·1 answer
  • Give a logical expression with variables p,q, and r that is true if p and q are false and r is true and is otherwise false.
    5·1 answer
  • . What is the output of this code sequence?
    8·1 answer
  • What are two best practices for discovering whether a message you’ve scheduled with Hootsuite has failed to send?
    8·2 answers
  • When you leave your computer for a short period of time, why should you put your computer into Standby mode?
    5·2 answers
  • Assume that processor refers to an object that provides a void method named process that takes no arguments. As it happens, the
    5·1 answer
  • Please help thank you !!!
    7·2 answers
  • Most portable devices, and some computer monitors have a special steel bracket security slot built into the case, which can be u
    13·1 answer
  • Which letter shows the ball when it has the maximum kinetic energy
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!