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
Anna35 [415]
3 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).\
Computers and Technology
2 answers:
vichka [17]3 years ago
8 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

Usimov [2.4K]3 years ago
6 0

Answer:

// Program segment is written in Java programming language

// Comments are used for explanatory purpose

// Program segment starts here

// Initialise the two in variable to 0

count = 0;

longest =0;

// define the string variable

String myString = new String();

// Check if scanner reference contains string using while iteration

while (input.hasNext()){

// Input string while condition is true

myString = input.next();

// Compare length of string with longest variable

if (myString.length() == longest)

{

// If equal, increment count by 1

count++;

}

// If length of string is greater than longest

else

if (myString.length() > longest)

{

longest = myString.length(); // assign length of string to longest

count = 1; // set count to 1

}

}

// End of code segment

You might be interested in
13. By adding built-in writable memory to its cartridge, Nintendo’s _________________ was the first console game that gamers cou
Rzqust [24]

The answer is c
Explanation:
5 0
3 years ago
Which of the following is the system of rules and structure governing
Whitepunk [10]

The system of rules and structure which governs language is generally referred to as: C. grammar.

<h3>What is language?</h3>

A language simply refers to a structured system of communication through which living organisms, especially humans share information among themselves, especially through the use of spoken words and sounds.

In English language, grammar is the system of rules and structure which governs the use and composition of language.

Read more on language here: brainly.com/question/781903

#SPJ1

8 0
2 years ago
Có n chiếc kẹo và m em bé. Hãy viết chương trình nhập vào hai số nguyên dương n, m và kiểm tra n chiếc kẹo có chia đều được cho
sleet_krkn [62]

uy ako ba yung pilipino dito hi nga kau

5 0
3 years ago
Answer this blank:<br><br> Air enters through the mouth or nose, and travels through the _
Schach [20]
Respiratory system ?. Or esophagus?
5 0
3 years ago
Read 2 more answers
¿Cómo es la onda percibida por un osciloscopio cuando hablamos de sonido? ¿Qué parámetros podemos observar en ella?
frozen [14]

Answer:

Las ondas de sonido, que es una onda longitudinal, son producidas por la vibración de un objeto de tal manera que (la onda de sonido requiere un medio de viaje, líquido sólido o gas) la dirección del sonido es la misma que la dirección de la vibración y como la el ancho de la vibración (hacia adelante y hacia atrás) aumenta, la amplitud de la vibración aumenta y el sonido es más fuerte

Un micrófono conectado al osciloscopio recoge el medio de aire vibrante de la onda de sonido de la energía de la onda de sonido y lo convierte (produce) señales eléctricas y electrónicas. El osciloscopio, que está diseñado para mostrar señales electrónicas, muestra las señales electrónicas transmitidas por el micrófono en la pantalla con los mismos valores de amplitud y frecuencia que el volumen y el tono de la onda de sonido, respectivamente.

Las características observables son;

1) El volumen o el volumen de la onda de sonido que se muestra como la amplitud) en el cátodo, con una amplitud más alta que representa un sonido más fuerte

2) El tono de la onda de sonido se muestra como el espaciado de onda en el osciloscopio, el sonido de tono más alto se muestra por las ondas que se acercan en la pantalla

Explanation:

7 0
3 years ago
Other questions:
  • What device brocasts all data packets to other nodes on a network?
    5·1 answer
  • Which type of operating system is usually used in personal computers?
    11·1 answer
  • Which date formats are allowed in Excel for February 14, 2018? Check all that apply.
    15·2 answers
  • A small, electronic chip that a manufacturer develops for use in another product (such as a digital camera or microwave oven) is
    11·2 answers
  • A digital designer might do computer animations for video games,<br> OA<br> True<br> OB<br> False
    12·2 answers
  • 8.Which of the following IC was used in third generation of computers?Immersive Reader
    13·1 answer
  • You can find synonyms and disciplinary jargon in the ______, _______, and ______ in your search results. You can then use these
    13·1 answer
  • Write a program that produces an expense report for a trip to Lagos, Nigeria. Use the Internet to research the cost to travel to
    13·1 answer
  • What is a functional organisation? and how it functions​?
    12·1 answer
  • a central issue in the microsoft antitrust lawsuit involved microsoft's integration of its internet browser into its windows ope
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!