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
__________ refers to rules, statutes, codes, and regulations established to provide a legal framework within which business may
Flauer [41]

Answer:

Business law

Explanation:

Business law are the laws that includes how to start, manage, sell, close a business. They include state and federal laws and administrative regulations.

I hope you find this information useful and interesting! Good luck!

7 0
3 years ago
Information technology has powerful effects on social behavior. Which of the following issues should NOT be expected when intera
AfilCa [17]

Increased inhibitions and a decreased likelihood that all members will contribute to the discussion is the following issues should NOT be expected when interacting with teammates via information technology

b. Increased inhibitions and a decreased likelihood that all members will contribute to the discussion.

<u>Explanation:</u>

In information technology, social behaviour will effect more powerful in industries. In digital medial those use mobile everybody is a media person, easily share the important to social media and sharing person doesn’t aware of the effect of sharing the information.

If a piece of information is received or send both the sender and receiver should be aware of the importance of information make sure it should not be shared outside the group members or the world.

Once import information shared outside the world it can stop any given point time.

6 0
3 years ago
Write a program that prompts the user for a measurement inmeters and then converts it into miles, feet, and inches.
zubka84 [21]

Answer:

Program for measurement in meters and then converts it into miles, feet, and inches:

#include<iostream.h>

#include<conio.h>

void main()

{  float meter, mile, feet, inches;

 cout<<"enter meters";

 cin>>meters";

 feet=meter×3.2808;

 mile= meter×0.000621371;

 inches= meter×39.3701;

cout<<"Value of"<<meter<<"meter"<<"in feet is"<<feet<<"feet":

cout<<"Value of"<<meter<<"meter"<<"in mile is"<<mile<<"mile";

cout<<"Value of"<<meter<<"meter"<<"in inches is"<<inches<<"inches";

getch();

}

8 0
3 years ago
You find information that you know to be classified on the internet. What should you do.
melomori [17]

A person is to find the information to be classified on the internet  are the best in the screenshot.

What is internet?

The word “internet” is also referred to as “net.” The global system of networks known as the Internet. Online services offered via the Internet include social media, email, and others. The without internet  are the not possible to share the information at the time.

A person is to find the information through which the internet is the best to justify. There used of the internet are the search the information with the help of the internet are the mic, keyboard. The information are the save and the screenshot was the used.

As a result, the person is to find the information to be classified on the internet  are the best in the screenshot.

Learn more about on internet, here:

brainly.com/question/13308791

#SPJ2

5 0
1 year ago
Read 2 more answers
When you add encryption to a powerpoint presentation what does it do
abruzzese [7]

Answer: your document will be inaccessible

5 0
2 years ago
Other questions:
  • 4. An outline is most like which of the following? (1 point)
    14·1 answer
  • Which of the following STEM discoverers developed a new type of computer hardware?
    11·1 answer
  • In the file MajorSalary, data have been collected from 111 College of Business graduates on their monthly starting salaries. The
    15·1 answer
  • It is important to name your files in a variety of formats. true or false
    15·2 answers
  • . Let F(X, Y, Z)=(X + Y + Z)(X + Y + Z)(X + Y + Z)(X + Y + Z). Use a 3-variable K-Map to find the minimized SOP form of this fun
    15·1 answer
  • Which of the following represents the biggest difference between asymmetric and symmetric cryptography?
    9·1 answer
  • Knowing the meaning of the acronym WAS I WHY can be most helpful to you when you?
    14·1 answer
  • _______________ ________________ have human editors that evaluate, select, and organize websites into a hierarchy of categories.
    11·1 answer
  • Write a program to find the sum of first 10 even numbers in qbasic​
    15·1 answer
  • What is a word processor write any five important features of word processor?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!