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
Python: Write a program for a small restaurant that sells pizzas. You may consider it as a prototype of a realistic online appli
katrin2010 [14]

Answer:

Name: tyler

Number of pizzas: 2

Small (10 inch, $7.95), Medium (12 inch, $9.95), and Large (14 inch, $11.95)

Pizza size: large

Available toppings: Ham, Mushrooms, Onions, Green Peppers, Black Olives, Tomatoes, Pineapple, Spinach

$0.75 each for Small Pizza, $0.95 each for Medium Pizza, and $1.15 each for Large Pizza

Number of toppings: 2

Enter topping number 1: ham

Enter topping number 2: onions

Order Summary:  

Customer Name: tyler

2 large pizzas with ['ham', 'onions']        

Subtotal | Sales Tax (6%) | Total Cost        

26.2 | 1.5719999999999998 | 27.772

Explanation:

name = input("Name: ")

num_pizzas = int(input("Number of pizzas: "))

print("Small (10 inch, $7.95), Medium (12 inch, $9.95), and Large (14 inch, $11.95)")

pizza_size = input("Pizza size: ").lower()

print("Available toppings: Ham, Mushrooms, Onions, Green Peppers, Black Olives, Tomatoes, Pineapple, Spinach")

print("$0.75 each for Small Pizza, $0.95 each for Medium Pizza, and $1.15 each for Large Pizza")

num_toppings = int(input("Number of toppings: "))

toppings = []

subtotal = 0

tax = 0

total = 0

for i in range(1,num_toppings + 1):

   toppings.append(input(f"Enter topping number {i}: "))

if pizza_size == 'small':

   subtotal += num_pizzas * 7.95

   subtotal += num_toppings * 0.75

   tax += subtotal * 0.06

   total += subtotal + tax

   print("Order Summary: ")

   print(f"Customer Name: {name}")

   print(f"{num_pizzas} {pizza_size} pizzas with {toppings}")

   print("Subtotal | Sales Tax (6%) | Total Cost")

   print(f"{subtotal} | {tax} | {total}")

if pizza_size == 'medium':

   subtotal += num_pizzas * 9.95

   subtotal += num_toppings * 0.95

   tax += subtotal * 0.06

   total += subtotal + tax

   print("Order Summary: ")

   print(f"Customer Name: {name}")

   print(f"{num_pizzas} {pizza_size} pizzas with {toppings}")

   print("Subtotal | Sales Tax (6%) | Total Cost")

   print(f"{subtotal} | {tax} | {total}")

if pizza_size == 'large':

   subtotal += num_pizzas * 11.95

   subtotal += num_toppings * 1.15

   tax += subtotal * 0.06

   total += subtotal + tax

   print("Order Summary: ")

   print(f"Customer Name: {name}")

   print(f"{num_pizzas} {pizza_size} pizzas with {toppings}")

   print("Subtotal | Sales Tax (6%) | Total Cost")

   print(f"{subtotal} | {tax} | {total}")

7 0
3 years ago
The OS that has a Dock is the<br> Linux<br> Mac<br> Windows<br> MS DOS
frutty [35]

Mac OS. As verified in the picture.

While some distros of Linux have docks, Mac OS started and is known for using a dock.

8 0
3 years ago
What is Digital Etiquette? Explain in your own words
madreJ [45]

Answer:

rules about the best way to communicate

Explanation

rules about being proper and polite

8 0
3 years ago
When mapping a drive, you can type in the path to the shared folder on the host computer. what is the syntax for the path?
fomenos
For SMB:  \\server\path\to\share
For CIFS: //server/path/to/share
3 0
4 years ago
You are hired as a security advisor to the software development team at ABC corporation. The team aims to develop a new electron
Sergeeva-Olga [200]

Answer:

✓ The best and most correct answer among the choices provided by the question is the second choice. Recent advancements in productivity software technology

Explanation:

Productivity software has been used for a number of years. Recent advancements in productivity software technology have made _____ among multiple users all over th…

✓ The best and most correct answer among the choices provided by the question is the second choice. Recent advancements in productivity software techn…

See more

7 0
3 years ago
Other questions:
  • HELP QUICK!!!
    14·2 answers
  • . Find four different commands in Internet Explorer and identify their keyboard shortcuts. A. B. C. D.
    10·1 answer
  • which of the following is not a windows accessory? a. sticky notes b. windows 8 c. sound recorder or d. paint
    8·2 answers
  • For the following data, what is the average number of cycles per instruction?
    10·1 answer
  • What is good prossesser
    15·2 answers
  • Which statement describes Augmented Reality (AR) technology?
    12·1 answer
  • This shows you where text will appear as you type.
    14·1 answer
  • Jabari created new video game for his coding course. What is one way he should format his pseudocode?
    12·1 answer
  • A restaurant recorded the ages of customers on two separate days. You are going to write a program to compare the number of cust
    15·1 answer
  • How many pixels are in a picture that is 640 pixels wide and 480 pixels high?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!