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
Fill in the blank with the correct term.
frozen [14]
Its bubble sort!!! Thats my final answer! Youre welcome
8 0
2 years ago
Read 2 more answers
What is the function of the keyboard shortcut Ctrl+Shift+E in a word processor
Masja [62]
<span>toggle your tracking on or off</span>
4 0
3 years ago
Read 2 more answers
For homework, we have to figure out what's in the picture. It's " too close to tell " but I can't figure out what it is. Any ide
CaHeK987 [17]
It seems like some type of fabric, maybe a car seat? i honestly don't know, sorry
4 0
3 years ago
Which of the following characteristics of an e-mail header should cause suspicion?A. Multiple recipientsB. No subject lineC. Unk
julsineya [31]

Answer:

The correct answer for the given question is option(b) i.e " No subject line"

Explanation:

In the e-mail subject is the important part which describe the information which kind of particular mail is send or received .if we do not give any subject line in the e-mail header then most of the chances that email will not read by recipients due to this suspicion will be caused.

Unknown Sender and Multiple recipients do not cause suspicion so the correct answer is option(b) i.e No subject line".

3 0
3 years ago
Will give brainliest!!!!!!!!!!!!
stira [4]
A trademark is a sign, symbol, name, or short phrase that indicates the source of a product or service.
3 0
3 years ago
Read 2 more answers
Other questions:
  • The part of the computer that provides access to the internet is the?
    14·1 answer
  • Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessar
    6·1 answer
  • It is an attribute that must be used in the form tag in specifying an input file type
    9·1 answer
  • ListenListen with ReadSpeakerAn administrator working on a Windows Server 2016 Server Core installation needs to disable DHCP on
    9·1 answer
  • What is WEB 1.0 to WEB3.0
    11·1 answer
  • You have added a table to your web page consisting of two columns and five rows, including the header row. in the first header c
    13·1 answer
  • User defined blocks of code can be created in
    13·1 answer
  • Question 2
    7·1 answer
  • • Do you think documentaries are best delivered in media such as films or documentary?
    10·1 answer
  • The Linux tail command prints the last maximum n lines of a file. When writing a function that performs this function, choose th
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!