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
Sincerely is an example of a salutation true or false
Setler79 [48]
No, I don't think so.
5 0
3 years ago
Read 2 more answers
What is the smallest group network
astra-53 [7]

LAN, MAN, MLAN, WAN, SAN, PAN ETC.

6 0
3 years ago
Someone please help me fill this out! Ill give u brainlest
Verizon [17]
<span>¿De qué manera participar en actividades extracurriculares?
¿Cómo ayudar a sobresalir en la solicitud de la universidad?
R: aprendes habilidades diferentes a las clases habituales, como lograr obtener una gran habilidad en la oratoria o ya sea aprendiendo mas sobre la literatura y aprender a componer poemas
<span><span>Si pudieras crear tu propio club u organización, ¿qué tipo de club u organización sería?
R : un club de robotica seria lo mas apropiado ya que aprenderemos a programar y llegar a comprender la mecanica de las aplicaciones que usamos a diario y al aprender a crear robots propios aprenderemos nuevas habilidades y aprender a confiar en nuestro propio criterio para que funcionen las cosas </span><span>¿Qué tipo de habilidades se requieren para estar en el club u organización?
R: debe tenerse un conocimiento muy basico en los lenguajes de programasion ya sea con solo entender la logica </span></span>
<span><span>¿Crees que una actividad extracurricular puede ser beneficiosa para obtener la carrera de tus sueños?
R: si, siempre y cuando la actividad extracurricular este relacionada con lo que deseamos ser en un futuro 
</span><span>¿Explica por qué o por qué no?
R: al tratarse de algo relacionado a la carrera que deseamos tendremos ya un conocimiento de lo que deberemos aprender y asi lograremos adaptarnos mas facilmente

</span></span></span>
3 0
3 years ago
Assume that a finite number of resources of a single resource type must be managed. Processes may ask for a number of these reso
nevsk [136]
The answer may not be found
5 0
3 years ago
How can you get feedback on your presentation from someone who is far away?
My name is Ann [436]

Answer:

C. Record your presentation...

I think this because if you want feedback you would definetly talk and record your presentation so the person can give you a clear response

8 0
3 years ago
Read 2 more answers
Other questions:
  • Which tab provide text formatting features
    11·1 answer
  • Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10,
    8·1 answer
  • Create a function named first_a that uses a list comprehension. The function will take a single integer parameter n. Find every
    13·1 answer
  • Write a method reverse( ) for OurLinkedList class. The method should return a new OurLinkedList object that is the reverse of th
    8·1 answer
  • HELP 25 POINTS!!!!!
    6·2 answers
  • There is an interface I that has abstract class AC as its subclass. Class C inherits AC. We know that C delegates to an object o
    12·1 answer
  • Write a method named removeRange that accepts an ArrayList of integers and two integer values min and max as parameters and remo
    10·1 answer
  • please help no one is helping me on this one
    9·1 answer
  • 1. What are you going to do if someone ask for your personal information online?​
    12·2 answers
  • A _____ system allows a customer to request a fax using email, via the company website, or by telephone.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!