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 of the following is true?
DENIUS [597]
D is the answer

Hope this helps
4 0
2 years ago
Why is it better for a CPU to have more than one cache?
Kitty [74]

Explanation:

i think cpu needs to have backup chache units in case of electrical failure

5 0
2 years ago
Read 2 more answers
Gabby is creating a game in which users must create shapes before the clock runs out. Which Python module should Gabby use to cr
igomit [66]
Uhh i think the answer is A
6 0
2 years ago
Read 2 more answers
application that will perform a lot of overwrites and deletes of data and requires the latest information to be available anytim
o-na [289]

Answer:

RDS.

Explanation:

A corporation has implemented a software that conducts the number of information overwriting and deleting, which allows the newest details to be accessible whenever the information is examined. As a Software Engineer, they suggest RDS database technologies.

It is an AWS supported controlled SQL DB service that also reinforces the array type DB for the purpose to contain and maintain the information.

3 0
3 years ago
What are the five layers in the internet protocol stack? What are the principal responsibilities of each of these lay?
mariarad [96]

Solution:

The five Layers in Internet protocol stack are:

1.Application Layer  

2.Transport Layer  

3.Network Layer  

4.Link Layer  

5.Physical Layer  

The principal responsibilities of these layers are as follows:

1.Application Layer •Applications with appropriate requirement for user.  

•It is reserved for network applications and their application protocols such as HTTP, SMTP, and FTP etc.  

•Its protocol uses transport layer protocols for establishing host-to-host connection.  

2.Transport Layer  

•It is responsible for End-to-Communication  

•Transport layer transports messages from application layer between client and server of application  

•It uses two protocol for transporting messages: TCP and UDP.TCP provides reliable connection oriented services, while UDP provides connectionless service  

3.Network Layer  

•Network Layer moves packets from one host to destination.

•It has two principal component:IP protocol:-It defines the datagrams and decide how the end system and router will work Routing protocols: these protocols decide the routing path between source and destination. 4.Link Layer  

•It is responsible for link-level communication  

•Link layer receives the data gram from network layer at each node and delivers it to next node, the next node passes the datagram to network layer.so This layer moves entire frames from one network element to adjacent one.

•The service provided by link layer is protocol dependent

5.Physical Layer  

•It provides Physical media

•At each node, it moves individual bits of frames to next node.  


7 0
3 years ago
Other questions:
  • Can you plug a usb 2.0 into a 3.0 port on your computer
    12·1 answer
  • List the steps in setting up an online banking account
    12·2 answers
  • Which institution developed outside the limits of the written costitution of the united states ?
    14·1 answer
  • Well the last week has been kind of terrible...
    9·2 answers
  • Describe the different
    12·1 answer
  • Write a Scientific report modeling a written reasearch paper on big data applications.​
    6·1 answer
  • What is malware? a type of virus that spreads through a network connection a type of virus that targets programs and files any p
    8·1 answer
  • Choose the missing words in the code below.
    12·1 answer
  • I'm in Paris and want to take a picture of my mom in front of the Eifel Tower. I want both her and the tower to be in sharp focu
    14·2 answers
  • What is software engineering? What are the objectives of software engineering?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!