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
What is an independent data mart?
steposvetlana [31]

Answer: Independent data mart is the subset of data that is obtained from the data warehouse in independent form. Various traits are used for the display of the independent data marts.They are built in the independent manner from each other .

It is utilized by the organization for the analysis of the certain unit of data in compact form. Independent data mart does not persist the central data warehouse. The operational sources gets distributed in the independent section known as data marts. It is usually preferred by small organizations.

7 0
4 years ago
Which sensitivity level is not a default available in Outlook 2016?
vichka [17]

Answer:

Company only

Explanation: The sensitivity levels available for Outlook 2016 are Normal, personal,private and confidential, this sensitivity levels helps users to the intentions of the user of the product and it will help to give their plan on what and how to utilize the product. It is very important to make use of the sensitivity levels in your Outlook for better usage of the Microsoft Outlook.

6 0
3 years ago
Read 2 more answers
How could the following line of code be shortened?
Alinara [238K]

Answer:

2

Explanation:

The second option is the only one that will work. The last would work but doesn't make the code any shorter.

8 0
2 years ago
Which of the following statements about security in the network is true?
Ilya [14]
I believe that answer A is true
5 0
3 years ago
You can access various sites on WWW by using hyperlinks or by?
wlad13 [49]
You can access various sites on WWW by using hyperlinks or by?

Answer is: A following directions on-screen
5 0
3 years ago
Read 2 more answers
Other questions:
  • In three to five sentences, describe how you can organize written information logically and sequentially
    8·1 answer
  • Rachel completed typing an official docment with a word processing program. She wants to make sure that her document has no typo
    15·2 answers
  • How to copy music from windows media player to pc?
    13·1 answer
  • Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed
    13·1 answer
  • What happens if the addressed device does not respond due to a malfunction during a read operation?
    11·1 answer
  • Write a calculator program using a switch statement that: a) Prompts the user to enter two numbers b) Prompts the user to select
    6·1 answer
  • In PowerPoint online what can you add to your presentation from the insert tab
    8·2 answers
  • What are node in a computer network​
    14·1 answer
  • What is data intergrity​
    13·1 answer
  • What was one effect of better printing methods during the Ming Dynasty? Updated trade routes A new merchant class Increased lite
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!