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]
3 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]3 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
Consider the following protocol for concurrency control. The database system assigns each transaction a unique and strictly incr
nasty-shy [4]

Answer:

(a) yes, this protocol allows only serializable schedules for transactions as due to this the system maintains it's consistency. As in this protocol a unique transaction id is being assigned and with the help of that transaction id the system would be able to identify the process which has taken place in what particular order. For example, in case of bank transfers

balance = 1000 transaction id 100

write ADD 200 transaction id 101

write SUB 1100 transaction id 102

write ADD 900 transaction id 103

in here with the help of transaction id we can check which operation has happened in which order, if not then some operation will not happen like 102 immediately after 100 and skipping 101

(b) the modified version of this protocol would be to also consider the time of transaction and take this factor in the consideration

4 0
3 years ago
Word Online works exact same as the downloaded Office 2016 version.<br>True<br>False​
melisa1 [442]

Answer:

The Answer is false. They work similarly but quite differently on a lot of offerings from them. Office 365 and office.com are online version, and Office 2016 is a desktop version.

Explanation:

I am not going very deep into this but the facts I am mentioning will clarify your doubts.

Office 2016 offers so many ways to share a file even though we work offline on it We can email the document, share on social media as well as store on One drive. However, Office 365, and especially Word online does not allow any other sharing options than sending an invitation or sharing a link.

For Word Online you will need internet all the time, though you can work from anywhere, and even on any device. Word 2016 does not require internet, but provide a lot of analytics features and even data mining facilities when it is connected to the internet.

Watch out for Word online 2019 version, and office 2019 desktop version. They are awesome and provides AI features, and a lot more than 2016 versions, both desktop and online.

3 0
3 years ago
Producers must understand the marginal benefit of making an additional unit which shows the ...
yan [13]

Producers must understand the marginal benefit of making an additional unit which shows the possible gain. Marginal benefit is used in business and economics as a measurement of the change in benefits over the change in quantity. Possible gain is one example of benefit.  This measurement provides the relevant measurement of benefits at a specific level of production and consumption.

8 0
3 years ago
Read 2 more answers
Which type of communication protocol converts data into standard formats that can be used by applications?
larisa86 [58]
<span>Arrival protocols are the type of data protocols that convert data into standard formats that can be used by applications, such as email, Web browsers and Skype</span>
8 0
3 years ago
All of the following are eras in IT infrastructure evolution except the​ ________. A. general purpose mainframe and​ mini-comput
Digiron [165]

Answer:

C: disruptive technology era

Explanation:

There are five main stages in IT infrastructure era and the are, in order from the oldest to the newest; the mainframe and minicomputer era, the personal computer era, the client/server era, the enterprise era, and the cloud computing being the newest in the five stages eras of IT infrastructure.

7 0
3 years ago
Other questions:
  • An electronic resume is a plain-looking document. True of False?
    6·2 answers
  • What technology process would help you access files at all times?
    11·1 answer
  • Which of the following statements invokes the GetDiscount function, passing it the contents of two Decimal variables named decSa
    8·1 answer
  • Why is brainly not working it say im logged out rn but im not i cant acces anything but this
    12·2 answers
  • Analyze the following code. Which of the following statements is correct?
    9·1 answer
  • the term that is used to describe how many bits are used in each pixel to show the number of colours used
    11·1 answer
  • 2. Which one of the following is not a feature of technology?
    10·1 answer
  • What do you call a commercial transaction beyween a buisness and buisness thatis transactedd online?
    7·1 answer
  • When must an Assured Equipment Grounding Conductor Program (AEGCP) be in place?
    13·1 answer
  • Any changes done to the software during the operational phase of the software before project wind up is called as maintenance. S
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!