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
Effective character encoding requires:
Dvinal [7]

To answer your question the answer would be B compatible browsers

8 0
3 years ago
What allows files containing text, programs, graphics, numerical data and so on to be downloaded off or uploaded onto a network?
Drupady [299]

Answer:

File Transfer Protocol

Explanation:

In computer networks and data communication, the client- server network architecture is very popular, in this network architecture, bigger computers designated as servers respond to clients request for information (This could be text, programs, graphics numerical data etc.) The File Transfer Protocol shortened as FTP is the standard network protocol that allows the transfer of these files between the clients and servers.

This protocol is build for the client server achitecture and it is the protocol by which files are shared between computers  on the internet.

5 0
3 years ago
the php function that is executed is a connection to a database cannot be made is the____ function. die | isset| end | connect.
Pepsi [2]

The PHP function that is executed is a connection to a database that cannot be made is the die() function.

An error is an undesirable programming outcome. The mistake is a subset of the error. Error management is a vital component of any website or programme.

Error handling is a mechanism for identifying errors that a programme makes and taking appropriate corrective action. This can be done by utilising die() method.

When a programming problem occurs, the software will halt further code execution and display the appropriate error message to the user. The die() function displays a message and terminates the running of the programme.

The connect() function in PHP is one that is used to establish a connection to a database.

The end() method in PHP is used to locate the final element of the specified array. The end() function updates an array's internal pointer to refer to the final element and returns that element's value.

The isset() function examines whether a variable is set, which implies that it has to be declared and is not NULL. If the variable is present and not NULL, this function will return true; otherwise, it will return false.

To learn more about PHP click here:

brainly.com/question/29740624

#SPJ4

4 0
2 years ago
The sign used for closing a tag is​
iragen [17]

Answer:

The sign used for closing a tag is answer is /.

Explanation:

I program all the time and when I am programming in HTML I use tags all the time so I basically memorized it.

8 0
3 years ago
Which aspect of nature inspired the invention of Velcro
lesya692 [45]

Burrs from plants (APEX)

8 0
4 years ago
Other questions:
  • What possible reason would explain why you are unable to connect to the intranet site on your computer’s web server, using a bro
    13·1 answer
  • Which of the following is the correct syntax for a hyperlink:
    7·1 answer
  • In a nondatabase, file-oriented environment, data is often partitioned into several disjointed systems with each system having i
    11·1 answer
  • If the speakers are not working on a laptop, what could be the problem besides the speakers?
    5·1 answer
  • Can you get in trouble for copying something you thought you were allowed too reddit?
    9·1 answer
  • In which type of modulation is a 1 distinguished from a 0 by shifting the direction in whichthe wave begins?
    14·1 answer
  • Problem # 1 [End of chapter problem] The following character encoding is used in a data link protocol: A: 01100111 B: 11110011 F
    14·1 answer
  • Blank Are input instructions you give to a computer
    13·1 answer
  • PLEASE HELP I WILL GIVE BRAINLIEST!!
    8·1 answer
  • Select the correct answer.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!