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
Which statement best characterizes under what circumstances you should add your social media profile to a resume? You should add
aliya0001 [1]

Answer:

You should add your profile, but it should be professional and positive.

Explanation:

this is the most reasonable response... resumes are for careers and professions.. so you must be professional and positive (if it is for example linkedin)

8 0
3 years ago
_________ is a business strategy in which a company purchases its upstream suppliers to ensure that its essential supplies are a
Korvikt [17]

Answer:

Vertical Integration

Explanation:

Vertical Integration is a business strategy in which a company purchases its upstream suppliers to ensure that its essential supplies are available as soon as the company needs them.  This enables the business to exercise higher control over supply related uncertainties and to optimize supplies based on changing demand or business priorities.

An example can be a textile manufacturer purchasing a dye manufacturing unit.

4 0
4 years ago
I need an excuse not to call someone. I hate using the phone. Any suggestions?
igor_vitrenko [27]

You can say that you lost your voice because you are currently ill.

4 0
3 years ago
Read 2 more answers
Another area where the Internet and the Web have had a huge influence is the workplace environment. How different do you think i
Strike441 [17]

Off the top of my head I know there was a lot of researching by means of books. Books were where you went to find information. So nowadays you can find everything with a search engine whereas you had to go to the bookstore back then.

4 0
3 years ago
What is the steps for opening paint application ​
Savatey [412]

you go to your windows at the bottom of your monitor. you then type in "paint" and click on what comes up. :)

7 0
3 years ago
Other questions:
  • What item on a business card is generally the most prominent?
    13·2 answers
  • You are working as a Software Programmer for one of the big retail company. You need to implement the program that can store at
    15·1 answer
  • Complete the method, longestWord(), below that takes in an array of Strings and returns the longest String in the array. Note: y
    8·1 answer
  • A _____ are devices that permit a user to connect to a digital t-carrier service.
    6·1 answer
  • Which of the following statements represents a scientific bias?
    15·1 answer
  • In his digital portfolio, Ben wants to locate each work he created. Where can he list details about the work in his digital port
    7·2 answers
  • A player moves around the screen with the arrow keys. Three enemies on the screen each have a different starting amount of hit p
    12·1 answer
  • Does anyone know how many Brainliests you need to be able to send a private message to someone??
    10·2 answers
  • What job does a front-end developer perform?
    15·1 answer
  • What type of program would you use to create a personal budget?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!