answer.
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
Ivanshal [37]
2 years ago
5

Given a Scanner reference variable named input that has been associated with an input source consisting of a sequence of strings

and two int variables, count and longest, write the code necessary to examine all the strings in the input source and determine how long the longest string (or strings are). That value should be assigned to longest. The number of strings that are of that length should be assigned to count.
Computers and Technology
2 answers:
Ghella [55]2 years ago
5 0

Answer:

count = 0;

longest =0;

String myString = new String();

while (input.hasNext()){

myString = input.next();

if (myString.length() == longest) count++;

else

if (myString.length() > longest){

longest = myString.length();

count = 1;

}

}

Explanation:

masya89 [10]2 years ago
4 0

Answer:

import java.util.Scanner;

public class LongestString

{

public static void main(String[] args) {

   

    int count = 0, longest = 0;

    Scanner input = new Scanner(System.in);

    Scanner in = new Scanner(System.in);

   

    System.out.print("Enter the size: ");

    int size = in.nextInt();

    String words[] = new String[size];

   

    for(int i=0; i<size; i++) {

        System.out.print("Enter a word: ");

        words[i] = input.nextLine();

    }

   

    String longestWord = words[0];

    for(int i=0; i<size; i++) {

       

        if (words[i].length() > longestWord.length()) {

            longestWord = words[i];

            longest = words[i].length();

            count = 1;

        }

        else if (words[i].length() == longestWord.length()) {

            longest = words[i].length();

            count++;

        }

    }

 System.out.println("The longest word: " + longestWord + "\nThe length: " + longest + "\nThe count: "+ count);

}

}

Explanation:

I provided the full code, getting the inputs and print the results, in addition to your request, so that it may be more clear.

-Ask the user for the array size of <em>words</em>, holds the strings entered by the user

- Inside the first <u>for loop</u>, initialize the <em>words </em>array

<em>- </em>Inside the second <u>for loop</u>, find the longest string, its length and the count of the string.

- Print the longest string, its length and count

You might be interested in
Explain working principle of computer?​
Sonbull [250]

Answer:

The working principle of the computer system. Computers do the work primarily in the machine and we can not see, a control center that converts the information data input to output. This control center, called the central processing unit (CPU), How Computers Work is a very complex system.

Explanation:

5 0
2 years ago
You would like the user of a program to enter a customer’s last name. Write a statement thaUse the variables k, d, and s so that
mojhsa [17]

Answer:

1st question:

Use the variables k, d, and s so that they can read three different values from standard input an integer, a float, and a string respectively. On one line, print these variables in reverse order with exactly one space in between each. On a second line, print them in the original order with one space in between them.

Solution:

In Python:

k = input()  #prompts user to input value of k i.e. integer value

d = input()  #prompts user to input value of d i.e. float value

s = input()  #prompts user to input value of s i.e. a string

print (s, d, k)  #displays these variable values in reverse order

print (k, d, s)#displays these variable values in original order

In C++:

#include <iostream>    // to use input output functions

using namespace std;   //to identify objects like cin cout

int main() {    //start of main function

  int k;   //declare int type variable to store an integer value

  float d; //  declare float type variable to store a float value

  string s;   //  declare string type variable to store an integer value

  cin >> k >> d >> s;    //reads the value of k, d and s

  cout << s << " " << d << " " << k << endl;     //displays these variables values in reverse order

  cout << k << " " << d << " " << s << endl;   } // displays these variable values in original order

Explanation:

2nd question:

You would like the user of a program to enter a customer’s last name. Write a statement that asks user "Last Name:" and assigns input to a string variable called last_name.

Solution:

In Python:

last_name = input("Last Name:")

# input function is used to accept input from user and assign the input value to last_name variable

In C++:

string last_name;  //declares a string type variable named last_name

cout<<"Last Name: ";  // prompts user to enter last name by displaying this message Last Name:

cin>>last_name; // reads and assigns the input value to string variable last_name

The programs alongwith their outputs are attached.

6 0
2 years ago
Menus are attached to windows by calling the _____ method.
Kruka [31]

Answer: setJMenubar

Explanation:Menus that are component of the Menu bar that display the options and tools for any function that can be performed in the system have the connection with the window in the field of java through the command of the setJMenubar. It is the command which is given to execute to bring the menu to the particular frame and get it attached according to the JFrame. Therefore, the correct option is setJMenubar.

6 0
2 years ago
Poor quality lateral communication will result in which ofthe
zhuklara [117]

Answer:

b

Explanation:

b, lack of coordination

3 0
2 years ago
Read 2 more answers
Which of the following is not one of the four criteria for evaluating websites?
Flura [38]

Answer:validity

Explanation:

Because it dont sound right

5 0
2 years ago
Other questions:
  • What are the two most important network-layer functions in a datagram network? what are the three most important network-layer f
    7·1 answer
  • The ________ program displays graphics and loading screens during the boot process.
    8·1 answer
  • 8. In time series, which of the following cannot be predicted? A) large increases in demand B) technological trends C) seasonal
    11·1 answer
  • A U.S. social security number consists of a string of 9 digits, such as "444422333". Assume that input consists of a sequence of
    6·2 answers
  • Given three dictionaries, associated with the variables, canadian_capitals, mexican_capitals, and us_capitals, that map province
    11·1 answer
  • There are no breakpoints in the "Access Customer Account" subpage however there is an error. What will happen if you choose to s
    11·1 answer
  • Information gathered from observing a plant grow 3 cm over a two-week period results in _______.a. inferences. b. variables. c.
    11·1 answer
  • Lin is booting up his computer, and during the boot process, the computer powers down. After several unsuccessful attempts to bo
    13·1 answer
  • Someone claims that the big O notation does not make sense at all, and they give the following example. An algorithm A that proc
    15·1 answer
  • You are using a polynomial time 2-approximation algorithm to find a tour t for the metric traveling salesman problem. Which of t
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!