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
Which option for creating a table involves the use of a grid of squares?
SSSSS [86.1K]
It’s draw table iirc
4 0
3 years ago
Read 2 more answers
____________________ is like a set of instructions that helps hardware process data into information.
Arte-miy333 [17]

Answer:

Program

Explanation:

Program is like a set of instructions that helps hardware process data into information.

Every hardware needs a program to process data into information.

For example take the example of a data processing software like MS Excel.

You open a spreadsheet and enter some data into your sheet. and then ask the program to do some calculations with this data and give you output results. The spreadsheet software does this processing in the background for you and provides you the results.

Without program a hardware doesn't know what to do with the data. Therefore, a program is like a instruction set that guides the hardware what to do with the data.

Note: The terms software and program are usually used together but there is a difference between software and program

A software is a generalized term and program is more like a specific term.

software can be made up of several different programs which performs many different tasks. On the other hand, a program only carry out a specific task or set of instructions.

3 0
3 years ago
The music is the soul who says this
Crazy boy [7]

Question:the music is the soul who says this

Answer: Arthur Schopenhauer

Explanation: he says music is the language of feeling and of passion

question answered by

(jacemorris04)

4 0
3 years ago
Michael and Ryan are athletes. They use digital devices as they try to improve their performance and when they relax. They are t
Maksim231197 [3]

Answer:

Firstly if that device is allowed in that country. Going to another country can be cool, provided that the restrictions are known. Certain countries don't allow the sale or use of certain digital products. To be sure of that digital device is allowed, Michael and Ryan should check the custom services of that country

Secondly, is the setup of the didgital devices. For example, Michael wants to use a GPS in the event. Then he needs to be sure whether the GPS is compatible with the new country or not. There can be varius problems in the GPS, most notably the time and the location.

Lastly, if they are relaxing, say watching funny videos on TV language shouldn't be a barrier.

Explanation:

Hope this helps... pls vote as brainliest

4 0
3 years ago
Suppose Animal is an interface that specifies a single method – speak. Now suppose the Dog class implements the Animal interface
Finger [1]

Answer / Explanation

To properly answer this question, let us define some basic terms within the narrative of the question.

This includes:

Speak Method: This is a type of java script or programming language syntax or method. The speak method usually denoted by the symbol () is a form of of Speech combination or the combination of components of different speech or elements to form a whole speech method. it is an interface that  adds an utterance to the utterance queue and  it will be spoken when any other utterances queued before it have been spoken.

Now, referencing the definition of speak method above and relating to the the options given as an output in the codes written in the answer options,

The answer here is (a) that is it will fail to comply which is equivalent to the option of it resulting to a compile time error.

7 0
3 years ago
Other questions:
  • __________ was the first operating system to integrate security as its core functions.
    15·2 answers
  • Write and run a Python program that asks the user for a temperature in Celsius and converts and outputs the temperature in Fahre
    10·1 answer
  • Who can help me please? ​
    14·1 answer
  • A ___________ is similar to Computer Integrated Manufacturing, but is based much more on standard reusable application software
    5·1 answer
  • Which of the following Google tools support collaboration? Docs Sheets Slides All of the Above
    13·1 answer
  • What is a directed graph?
    5·1 answer
  • Write a program with a method computeCommission which takes a double that is the salesAmount and returns the commissions for sal
    9·1 answer
  • What is the meaning of Re:?
    12·2 answers
  • Given two input integers for an arrowhead and arrow body, print a right-facing arrow.
    15·1 answer
  • I need the answer asap !!!!
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!