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
Ivanshal [37]
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). 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]3 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]3 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
"When analyzing the IDS logs, the system administrator notices connections from outside of the LAN have been sending packets whe
lakkis [162]

This is false negative. To be marked for alert.

<u>Explanation:</u>

The network administrator or network engineer when he or she is analyzing IDS logs and founded the ip address is same on source and destination both in outside side.

So the either TCPIP address has to change to be scanned across the network. Since same IP address is same pinging rate will high and pinging the same workstation or desktop or laptop.

Alert will not generate because both tcpip address same and if pinging is success.  Ids logs generates based true negative, true positive and false positive will not generate any alert.

5 0
4 years ago
What does this mean in python?
scoundrel [369]

the comments in the code should explain everything, brainly's formatting might be weird


gate = raw_input("Enter logic gate :").upper()#.upper() so lower/upper case of input doesn't matter

firstInput = raw_input("Enter first input :")#raw_input() for python 2.7, input() for 3

secondInput = raw_input("Enter second input :")

if (firstInput!="0" and firstInput!="1") or (secondInput!="0" and secondInput!="1"):

print("inputs must be 0 or 1")#ensure all inputs are in boolean range

quit()


firstInput=firstInput=="1"#convert "1" to true and "0" to false

secondInput=secondInput=="1"


if gate=="AND" or gate=="NAND":

result=firstInput and  secondInput

elif gate=="OR" or gate=="NOR":

result=firstInput or secondInput

elif gate=="XOR":

result=firstInput!=secondInput

else:#handle case of unknown/mistyped gates

print(gate+" is not known")

quit()

if gate=="NOR" or gate=="NAND":

result=not result#invert result for nor and nand

print("Result = "+str(int(result)))#uses int so 1/0 are printed instead of True/False


8 0
3 years ago
Earth’s atmosphere helps block out poisonous rays of radiation from outer space, thus helping support life on Earth.
anyanavicka [17]
The answer to this is True.
4 0
3 years ago
What is a feature only used in powerpoint
olga_2 [115]

I think powerpoint is the only presentation maker in which you can use 3D objects

6 0
3 years ago
Drag each label to the correct location on the image
tamaranim1 [39]

Answer:

huhhhhhhhhhhhhhhhhhhhh

7 0
3 years ago
Read 2 more answers
Other questions:
  • Attribute that contains only digits as a character data type instead of a numeric data type
    8·1 answer
  • ¿Por qué es importante generar proyectos innovadores?
    8·1 answer
  • In 1-2 sentences, describe some keyboard shortcuts you have used during this lesson to save you time.
    13·2 answers
  • How do you change colors for presentation to blue warm in power point?
    11·1 answer
  • Why does a CPU need Thermal Grease?
    14·1 answer
  • What is the benefit of making an archive folder visible in the Outlook folder list?
    6·1 answer
  • Which font is most suitable for an academic article on a website? Which is most suitable for casual information?
    5·2 answers
  • Which of the following is adoptable in Mindanao only?​
    5·1 answer
  • If you answer these questions correctly I will mark you BRAINLIST.
    7·1 answer
  • 10.13 lab 10c: output range with increment of 5 write a program whose input is two integers. output the first integer and subseq
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!