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
Why crt and plasma are not used in laptop ?​
AlekseyPX

Answer:

Plasma monitors are power hungry devices 2 - 3 times more than a CRT monitor making this technology unfit for use in portable devices like laptop computers where batteries are used as the power source. Plasma monitors are extremely susceptible to screen burn.

Explanation: pls mark my answer as brainlist

6 0
3 years ago
For which product would the producer keep a high profit margin and offer after-sales service?
Zina [86]

What are the products?

6 0
4 years ago
Determine the "answer" to the function according to the spreadsheet below: =SUM(A1:A3)/2
nataly862011 [7]
If this is the full question " <span>Which of the following formulas is equivalent to =SUM(A1:A3)? A. =A1+A3 B. =A1+A2+A3 B. =A2 D. =A3-A1"


The answer is </span>
<span>B. =A1+A2+A3 formulas is equivalent to =SUM(A1:A3)</span>
4 0
3 years ago
Allison is preparing to modify a network access control list and add three firewall rules to her private cloud HR systems. She i
Yakvenalex [24]

C. Change management

Allison is preparing to modify a network access control list and add three firewall rules to her private cloud HR systems by following the Change management process.

What exactly is change management?

Change management is the process of developing and implementing effective change strategies in businesses and organizations.

Examining the reasons for change, implementing changes, and assisting people in adapting to these changes are all part of it. This could include reorganizing the workforce, implementing new technology, lowering costs, increasing profits, or a combination of these to achieve a specific goal.

To know more about Change management, visit: brainly.com/question/28096717

#SPJ4

4 0
1 year ago
To prepare a list of the ten largest cities in Asia, Luke should most likely use data to
kakasveta [241]
He should find answers about the population size hope this helps 
5 0
3 years ago
Read 2 more answers
Other questions:
  • Which are characteristics of pseudocode? Select all that apply.
    6·1 answer
  • ________ is a software that interprets java bytecode.
    12·1 answer
  • Getting access to web browsing software to install it on a computer or to update your existing software is called _________ .
    9·2 answers
  • To increase the view of a document on the screen, use the _____. View icon Zoom slider full-screen reading boldface font
    9·1 answer
  • a corporation needs an operating system that allows the various teams in its office to network &amp; collaborate on projects. wh
    11·2 answers
  • When working on developing an ability, it is important to get feedback to know how you are doing.
    6·1 answer
  • According to the stage-gate process developed by Robert G. Cooper, _____ are the results of the previous stage and are the input
    15·1 answer
  • 5. An entrepreneur who continues to find new and better ways of doing things is ____.
    10·1 answer
  • Which girl is he baddest 1. Shawty 2.Lisa 3.Ashley
    9·1 answer
  • Find the name of the professor with the maximum percentage of students that failed his course.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!