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
maria [59]
3 years ago
14

Write a program that uses a scanner to report some statistics about words in an input sentence ( see Section 7.8). The outputs s

hould be the number of words in the sentence, the average word length, and the length of the sentence.
Computers and Technology
1 answer:
Alla [95]3 years ago
8 0

import java.util.Scanner;

public class JavaApplication77 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a sentence:");

       String sentence = scan.nextLine();

       String [] arr = new String[sentence.length()];

       arr = sentence.split(" ");

       System.out.println("There are "+arr.length+" words in the sentence.");

       int count = 0;

       for(int i = 0; i < arr.length; i++){

           count += arr[i].length();

       }

       System.out.println("The average length of a word in your sentence is "+(count/arr.length)+" characters");

       count = 0;

       System.out.println("Your sentence is "+sentence.length()+" characters long.");

       

   }

   

}

For the length of a sentence, I included spaces as characters but I did not do this for the length of a word. I hope this helps!

You might be interested in
The length of a hailstone sequence is the number of terms it contains. For example, the hailstone sequence in example 1 (5, 16,
11111nata11111 [884]

Answer:

Following are the program to this question:

#include <iostream> //defining header file

using namespace std;

int hailstoneLength(int n) //defining method hailstoneLength

{

int t=1; //defining integer variable assign  

while(n!=1) //define a loop that checks value is not equal to 1

{

if(n%2==0) // check even number condition

{

n=n/2; // divide the value by 2 and store its remainder value in n

t++; //increment value of t by 1.

}

else

{

n=n*3+1; //calculate and hold value in n  

t++; //increment value of t variable by 1  

}

}

return t; //return value

}

int main() //defining main method

{

int n; //defining integer variable

cout<<"Enter any number: "; //print message

cin>> n; //input value

cout<<hailstoneLength(n); //call method and print its value

return 0;

}

Output:

Enter any number: 3

8

Explanation:

Program description can be given as follows:

  • In the given C++ language program an integer method "hailstoneLength", is declared, that accepts an integer variable "n" in its parameter.
  • Inside the method, an integer variable t is declared, that assign a value that is 1, in the next line, a while loop is declared, that uses if block to check even condition if number is even it divide by 2 and increment t variable value by 1.
  • If the number is odd it will multiply the value by 3 and add 1 and increment t by 1 then it will go to if block to check value again. when value of n is not equal to 1 it will return t variable value.
  • In the main method, an integer variable "n" is used that call the method and print its return value.
7 0
3 years ago
What is the answer to 4.9 Code Practice: Question 2
bixtya [17]

Answer:

sum = 0

for i in range(20, 100, 10):

sum = sum + i

Print(sum)

Explanation:

7 0
3 years ago
Write an expression that executes the loop while the user enters a number greater than or equal to 0.
LekaFEV [45]

Answer:

while (userNum >=0) {...}

Explanation:

In a <u>while loop</u>, <u>the loop is executed until the condition is false</u>.

Since the loop will execute while the user enters a number greater than or equal to 0 (and that number is declared as <em>userNum</em>), we need to check if <em>userNum</em> is greater than or equal to 0.

4 0
3 years ago
What two different passwords can be set to lock down a computer from unauthorized access?
Shalnov [3]

The two different passwords you can use to lock down a computer from unauthorized access would be,

1. The Supervisor password

2. The User Password.

- Mabel <3

3 0
3 years ago
Which statement reflects an opinion about technology? Select all that apply. Select one or more: a. It is easy to imagine that a
True [87]

Answer:

All options apply to the question because each one reflects one side of technology in relation to the artist's case (that could be a software engineer or a even a hardware designer).

Explanation:

Letter a applies to the question in terms of computer program's behavior with no people's assistance, which is something not real for the present time, although it is easy to imagine that it is going to be a reality in a near future for all the improvements engineers and developers have made. Letter b also applies because computers and softwares have become one of the most important tools for artists around the world, whether for researching and/or for sharing and/or selling their productions, however it is a radical idea to think an artist is not necessary anymore, that is similiar to say human beings are not necessary only because machines have improved. Letter c also applies to the question for all improvements made in art and art forms after all improvements made in technology and tools for technologies development. And, letter d also applies because computers may be used for studying and/or working, which is the perfect tool for a workplace, and this is why it has become essential in many organizations, companies, subsidiaries, agencies, schools, and more.

3 0
3 years ago
Other questions:
  • Number Analysis Program: Write a program that reads data from the text file numbers.txt. Assume the file contains a series of nu
    14·1 answer
  • Design a 4-bit register that can accept an input from the user and store the accepted input. The 4-bit register will operate in
    6·1 answer
  • Operating systems that have windows and icons have which type of user interface?
    15·1 answer
  • FREE 100 POINTS + FIRTS AWNSER = BRAINIST
    8·2 answers
  • One of the functions of an IDE is to check for: flowchart errors. Syntax errors. memory errors X input and output.​
    12·2 answers
  • The costs incurred when a firm buys on the marketplace what it cannot make itself are referred to as
    6·1 answer
  • What is the FaFASA4caster used for
    10·1 answer
  • when working with smart which tab would provide the ability to change the shape or size of the smart art shapes
    15·2 answers
  • Jill is configuring the AutoArchive feature in Outlook 2016. What is the default setting in relation to when AutoArchive
    8·1 answer
  • In cell b12 create a formula using max f7nction to calculate maximum value in B4:B9
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!