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
Ainat [17]
2 years ago
6

Write code which takes a sentence as an input from the user and then prints the length of the first word in that sentence.

Computers and Technology
1 answer:
Afina-wow [57]2 years ago
7 0

import java.util.Scanner;

public class U2_L3_Activity_Four {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

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

       String sent = scan.nextLine();

       int count = 0;

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

           char c = sent.charAt(i);

           if (c != ' '){

               count++;

       }

           else{

               break;

           }

       

   }

       System.out.println("The first word is " + count +" letters long");

   

   }

}

We check to see when the first space occurs in our string and we add one to our count variable for every letter before that. I hope this helps!

You might be interested in
Implementations <br> in c++ programming when finding lcm and gcd in c++​
vazorg [7]

Answer:

#include<iostream>

using namespace std;

int lcm(int m, int n) {

  int a;

  a = (m > n) ? m: n;

  while (true) {

     if (a % m == 0 && a % n == 0)

        return a;

        ++a;

  }

}

int gcd(int m, int n) {

  int r = 0, a, b;

  a = (m > n) ? m : n;

  b = (m < n) ? m : n;

  r = b;

  while (a % b != 0) {

     r = a % b;

     a = b;

     b = r;

  }

  return r;

}

int main(int argc, char **argv) {

  cout << "Enter the two numbers: ";

  int m, n;

  cin >> m >> n;

  cout << "The LCM of two numbers is: " << lcm(m, n) << endl;

  cout << "The GCD of two numbers is: " << gcd(m, n) << endl;  

  return 0;

}

Explanation:

7 0
2 years ago
Give five functions of Windows​
Nata [24]

Answer:

Explanation:

It knows how to remember data and where to find that data. In other words, it knows how the raw memory works. (RAM).

It understands how to make a program run within the confines of its logical steps in an order that makes the program work the way the user intends.

It can be made to display short cuts, or any icon or picture (not an obvious talent).

It can search for unwanted intruders like ads or viruses.

It can can time events even to the point of getting your coffee ready for you with the proper add on.

6 0
2 years ago
Suppose you are an ad-serving company and you maintain a log of cookie data for ads you serve to the Web pages for a particular
Firlakuza [10]

Answer:

A

Explanation:

thethe more you have attached the more people are going to know your product so that it's going to be a long process which people can introduce to their friends

3 0
2 years ago
Huffman trees use the _________ of each character to work out their encoding. A) Frequency B) Order in ASCll
Maurinko [17]
I think the answer is C but I could be wrong
5 0
2 years ago
Convert infix to postfix
kvv77 [185]

Answer:

static int checkSymbol(char ch)

{

switch (ch)

{

case '+':

case '-':

return 1;

case '*':

case '/':

return 2;

case '^':

return 3;

}

return -1;

}

static String convertInfixToPostfix(String expression)

{

String calculation = new String("");

Stack<Character> operands = new Stack<>();

Stack<Character> operators = new Stack<>();

 

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

{

char c = expression.charAt(i);

if (Character.isLetterOrDigit(c))

operands.push(c);

else if (c == '(')

operators.push(c);

 

else if (c == ')')

{

while (!operators.isEmpty() && operators.peek() != '(')

operands.push(operators.pop());

 

if (!operators.isEmpty() && operators.peek() != '(')

return NULL;    

else

operators.pop();

}

else

{

while (!operators.isEmpty() && checkSymbol(c) <= checkSymbol(operators.peek()))

operands.push(operators.pop());

operators.push(c);

}

}

while (!operators.isEmpty())

operands.push(operators.pop());

while (!operands.isEmpty())

calculation+=operands.pop();

calculation=calculation.reverse();

return calculation;

}

Explanation:

  • Create the checkSymbol function to see what symbol is being passed to the stack.
  • Create the convertInfixToPostfix function that keeps track of the operands and the operators stack.
  • Use conditional statements to check whether the character being passed is a letter, digit, symbol or a bracket.
  • While the operators is  not empty, keep pushing the character to the operators stack.
  • At last reverse and return the calculation which has all the results.
4 0
2 years ago
Other questions:
  • What types of data are commonly entered into a cell ?
    7·2 answers
  • Encryption is the process of:
    12·1 answer
  • What is the purpose of the overload keyword in the ip nat inside source list 1 pool nat_pool overload command?
    8·1 answer
  • The isometric projection camera technique provides an illusion of perspective by using things like parallax scrolling to create
    10·1 answer
  • Letter Frequency Write a function that will take a string and return a count of each letter in the string. For example, "my dog
    5·1 answer
  • Write out the base sequence that is added directly after the primer. In order for Moodle to correctly grade this question, write
    11·1 answer
  • With Voice over Internet Protocol (VoIP), _____. a. voicemails cannot be received on the computer b. call quality is significant
    6·1 answer
  • PLEASE HELP ME I WILL GIVE BRAINIEST AND 40 POINTSPython Project Worksheet
    12·1 answer
  • JUST MAXED OUT THE COMMENTS anyways come here
    7·2 answers
  • A group of two or more computer systems linked together via communication devices is called:.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!