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
Sidana [21]
3 years ago
14

Write a program that will ask the user to input a phrase (multiple word sentence), and an integer value. A static function will

be created that takes the sentence (string) and integer as input parameters and returns a single word (string) of that sentence. If the integer was the number three, then the word returned would be the third word in the sentence. If the integer given in zero or negative, simply return an empty string. (do not let it crash) If the integer given is higher than the number of words in the sentence, then just return the last word.

Computers and Technology
1 answer:
Andreyy893 years ago
4 0

Answer:

See explaination

Explanation:

import java.util.Scanner;

public class Word

{

public static void main(String args[])

{

Scanner read=new Scanner(System.in);

char repeat='Y';

String phrase=null;

int index=0;

while(repeat=='Y')

{

System.out.println("enter a phrase :");

phrase=read.nextLine();

while(index<=0)

{

System.out.println("enter an index greater than 0");

index=Integer.parseInt(read.nextLine());

}

String s;

int spaces = phrase == null ? 0 : phrase.length() - phrase.replace(" ", "").length();

int numofwords=spaces+1;

if(index>numofwords)

{

index=numofwords;

}

System.out.println("word is: "+ getWord(phrase,index));

System.out.println("do you want to repeat (Y/N)");

repeat=read.nextLine().charAt(0);

index=0;

}

read.close();

}

private static String getWord(String phrase, int index) {

// TODO Auto-generated method stub

Scanner in =new Scanner(phrase);

String word=null;

int wordindex=0;

while(wordindex!=index)

{

word=in.next();

wordindex++;

}

in.close();

return word;

}

}

Check attachment screenshot

You might be interested in
PLEASE HELP!! HELP ME
Sav [38]
The answer is C

mark me as branliest if this helped
8 0
3 years ago
what is the term for software that is exclusively controlled by a company, and cannot be used or modified without permission?
zalisa [80]

Answer:

Proprietary Software

Explanation:

7 0
3 years ago
Code in Java:
OverLord2011 [107]

Answer:

Explanation:

The following expressions are written in Java and require the rest of the "assummed code" to run correctly, but can be pasted to that code and it has already been tested to be working and be bug free.

1)  boolean areEqual = (a1.getName() == a2.getName());

2) ch = c1.getModel().charAt(2);

3)  public static void whatIsStatus(Lamp myLamp) {

       if (myLamp.status == true) {

           return "ON";

       } else if (myLamp.status == false) {

           return "OFF";

       } else {

           return "ERROR";

       }

   }

4 0
3 years ago
What is the most popular type or method of guaranteed reservation where booking transactions will be charged automatically?
Rzqust [24]

Answer:

Credit cards.

Explanation:

When booking a reservation, the most popular type or method of making sure the reservation is guaranteed where booking transactions are charged automatics is the use of credit cards.

Why this is popular is because, the hotel, reserve or suite that is about to be booked will still receive their money even if the person that booked didn't show up.

4 0
3 years ago
2) List three (3) negative impact of Technology on society
Nataly [62]

Answer:

1. social media and mobile devices may lead to psychological.

2. They may contribute to more serious health conditions such as depression.

3. The overuse of technology may have a more significant impact on developing children and teenagers.

Explanation:

may this help you have a good day

5 0
3 years ago
Other questions:
  • What is the transfer rate of DDR memory?<br> A. 16 bit <br> B. 32 bit <br> C. 64 bit <br> D. 128 bit
    11·2 answers
  • Which letter indicates the amplitude of the wave?<br> a. A<br> b. B<br> c. C<br> d. D
    12·1 answer
  • Question 14 (3 points)
    5·1 answer
  • Making an analogy between Freudian theory and the brain networks described in an earlier chapter in the text, primary process th
    10·1 answer
  • 2. What is software conflict?<br>​
    11·1 answer
  • Dispositivo de computo
    5·1 answer
  • True or false. The CPU requires it's own power from the power supply, and can't receive power from the motherboard.
    9·1 answer
  • Life was not easier a century ago<br><br>​
    9·2 answers
  • List three variables that could be used in creating a model that determines the best day to plant corn in a given location. 30 p
    10·1 answer
  • You have a server that has a 100basefx network interface card that you need to connect to a switch. the switch only has 100baset
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!