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]
3 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]3 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
A simulation model includes: a. a description of the components of the system. b. a simulation clock. c. a definition of the sta
zloy xaker [14]

Answer: all of the above

Explanation:

8 0
3 years ago
Configuring a firewall to ignore all incoming packets that request access to a specific port is known as ____.
Sati [7]

Answer: Logical Point Blocking

Explanation:

4 0
1 year ago
Write a program that converts a number entered in Roman numerals to decimal.
Montano1993 [528]

Answer:

Here is the JAVA program:

import java.util.Scanner;   // for importing scanner class

public class RomanToDecimal{  //class to convert roman numeral to decimal

       static String romNum;  // variable that stores roman numeral

       static int decNum;  //variable that stores decimal number

       public static void main(String args[]) {  //start of the program

              //romtodec object created

              RomanToDecimal romtodec = new RomanToDecimal();  

//call function decimalConversion() that converts roman numeral to decimal

              romtodec. decimalConversion();  

//call function displayRomanNumeral to display the results of conversion

               romtodec. displayRomanNumeral(romNum);

//call function to display the decimal no. of roman numeral

               romtodec . displayDecimalNumber(decNum);   }

//method decimalConversion to convert Roman numeral to decimal

     public void decimalConversion () {

     Scanner scan = new Scanner(System.in);  //to get input

       //prompts user to enter a Roman numeral

     System.out.print("enter a Roman numeral: ");

               romNum = scan.nextLine();  //reads input    

               //stores the length of the entered Roman numeral                                            

                int length=  romNum.length();  

               int number=0;  //initializes number to 0

               int prevNum = 0;  //initializes previous number to 0

          //loops through the length of the input Roman numeral

               for (int i=length-1;i>=0;i--)  

//charAt() method returns the roman numeral symbol at the index i

               { char symbol =  romNum.charAt(i);

       //every symbol will be converted to upper case

                       symbol = Character.toUpperCase(symbol);

//switch statement tests the symbol variable for equality against a list of //numerals given and each numeral is assigned its equal decimal value.

                         switch(symbol)

                       {   case 'I':

                               prevNum = number;

                               number = 1;

                               break;

                            case 'V':

                                    prevNum = number;

                               number = 5;

                               break;

                               case 'X':

                                       prevNum = number;

                               number = 10;

                                break;

                               case 'L':

                                       prevNum = number;

                               number = 50;

                               break;

                               case 'C':

                                        prevNum = number;

                               number = 100;

                               break;

                               case 'D':

                                        prevNum = number;

                               number = 500;

                               break;

                               case 'M':

                                        prevNum = number;

                               number = 1000;

                               break; }          

/*checks if the number is greater than previous number

if the value of current roman symbol (character) is greater than the next

symbol's value. then add value of current roman symbol to the decNum

else subtract the value of current roman symbol from the value of its next symbol. */              

                       if (number>prevNum)

                           { decNum= decNum+number;  }

                       else

                          decNum= decNum-number;  }

//displays the decimal value of the roman numeral

       public static void displayRomanNumeral (String romNum){

               System.out.println ("The Roman numeral "+romNum+" is equal to decimal number"+decNum); }

//displays the number as decimal

           public static void displayDecimalNumber (int decNum){

       System.out.println ("The decimal number is: " + decNum);  } }      

Output:

enter a Roman numeral: MCXIV

The Roman numeral MCXIV is equal to decimal number 1114

Output:

enter a Roman numeral: CCCLIX

The Roman numeral CCCLIX is equal to decimal number 359

Output:

enter a Roman numeral: MDCLXVI

The Roman numeral MDCLXVI is equal to decimal number 1666

5 0
4 years ago
You have observed that Alexander Rocco Corporation uses Alika’s Cleaning Company for its janitorial services. The company’s
Rzqust [24]

Answer:

Explanation:

Relevance of Thrown Items:

  •    The thrown items mainly consist of the Windows NT training kit, outdated magazines and some written notes, etc. All these things can be used in the company for training the fresh talent.
  •    These things must be used for the purpose of training fresh people and the things like programs written in HTML must not be dumped like this because they consists of the raw code which can be harmful if gotten into wrong hands.
  •    Hence, the information like this must be taken care of seriously as these can be loopholes into companies down.
  •    Rest of the things like food wrappers, empty bottles, resume copies are all worthless to the company and can be thrown into the dump as soon as possible.The business cards must also be thrown if not important.

Recommendation To Management:

  •    The management must take these things seriously and must double check the company properties before throwing them into dump. There must be a committe build to check the things that are been going directly to the dump.
  •    They must have the responsibility for checking the things before going to the dump and must filter all the important things from the garbage back to the shelves of the office.
  • Hence, these things must be taken care of so that no harm is to be done to the company.

cheers i hope this helped !!

5 0
4 years ago
Compute the present value of a $5,500 deposit in year 1, and another $5,000 deposit at the end of year 4 using an 8 percent inte
marusya05 [52]

Answer:

Explanation:

Present value is the value in the present of a sum of money, in contrast to some future value it will have when it has been invested at compound interest.

It can be calculated using future value formula below

A = P(1+r/100)^n

where

A = Future value

P = Present value

r = Rate of interest

n = time period

Present Value = Value at Year 1 + Value at Year 4

Calculating Value at Year 1

A = $5,500

r = 8%

n = 1

From A = P(1+r/100)^n ; Make P the subject of formula

P = A ÷ (1 + r/100)^n

Substitute in values

P = $5,500 ÷ (1 + 8/100)^1

P = $5,500 ÷ (1 + 0.08)

P = $5,500/1.08

P = $5092.5925926

P = $5092.59 ----

Present Value at Year 1 = $5092.59

Calculating Value at Year 4

A = $5,000

r = 8%

n = 1

From A = P(1+r/100)^n ; Make P the subject of formula

P = A ÷ (1 + r/100)^n

Substitute in values

P = $5,000 ÷ (1 + 8/100)⁴

P = $5,000 ÷ (1 + 0.08)⁴

P = $5,000/1.08⁴

P = $3675.149263982267

P = $3675.15 ----

Present Value at Year 4 = $3675.15

Present Value = Value at Year 1 + Value at Year 4

Substitute each value

Present Value = $5092.59 + $3675.15

Present Value = $8,767.74

8 0
4 years ago
Other questions:
  • You can increase your efficiency by using your e-mail program's spell checker because it eliminates the need for you to proofrea
    11·1 answer
  • DSSS uses a chipping code to encode redundant data into the modulated signal. Which two of the following are examples of chippin
    12·1 answer
  • The 'parseInt' method of the 'Integer' class throws a 'NumberFormatException' when it is passed a String argument that it cannot
    11·1 answer
  • 97 points pleaseeee helpppp
    8·2 answers
  • Accessing disk is much slower than accessing memory. As a result, many file systems have been designed with various optimization
    7·1 answer
  • Electrical sign connect mainly to​
    8·1 answer
  • What is binary number system? Why is it used in computer system?
    13·2 answers
  • Submit your business presentation that clearly compares and contrasts three different cell phone service plans. I have TO HAVE I
    14·1 answer
  • Abby has received a request for a data set of actual data for testing a new app that is being developed. She does not want the s
    13·1 answer
  • the advertisement below is an example of a(n) the advertisement below is an example of a(n) informative advertising objective pe
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!