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
Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create
zaharov [31]

Answer:

See attached file.

Explanation:

See attached file for detailed code.

Download txt
7 0
3 years ago
Find the double word-length 2's complement representation of each of the following decimal numbers:a. 3874
miss Akunina [59]

Answer:

-3874₁₀ = 1111 1111 1111 1111 1111 1111 1101 1110₂

Explanation:

2's complement is a way for us to represent negative numbers in binary.

To get 2's complement:

1. Invert all the bits

2. Add 1 to the inverted bits

Summary: 2's complement = -N = ~N + 1

1. Inverting the number

3874₁₀ = 1111 0010 0010₂

~3874₁₀ = 0000 1101 1101₂

2. Add 1 to your inverted bits

~3874₁₀ + 1 = 0000 1101 1101₂ + 1

= 0000 1101 1110₂

You can pad the most signigicant bits with 1's if you're planning on using more bits.

so,

12 bits                          16 bits

0000 1101 1110₂  = 1111 0000 1101 1110₂

They asked for double word-length (a fancy term for 32-bits), so pad the left-most side with 1s' until you get a total of 32 bits.

           32 bits

= 1111 1111 1111 1111 1111 1111 1101 1110

7 0
3 years ago
Your ipad has an application that will not stop running. what feature/tool can you use to stop it? kill treason task manager for
saveliy_v [14]

you could force quit

6 0
2 years ago
Read 2 more answers
When an entrepreneur has three employees at a busy and growing software company, what is the primary responsibility of the emplo
Sloan [31]

Answer:

A: Create the product that customers

Explanation:

I did it on edgy

5 0
3 years ago
Which of the following is a set of short-range wireless technologies used to share information among devices within about two in
8_murik_8 [283]

Answer:

Option (c) NFC

Explanation:

  • The NFC Technology is a Wireless Technology which works in the range of 10 cm or less.
  • NFC stands for Near Field Communications.
  • The name itself indicates that it a communication mode with the near by objects.
  • The NFC technology is used in Access Cards, Payment Cards and Mobile Devices etc.
  • Option (a) IM - Instant Messaging is the instant text messaging technology sends and receives messages over the internet. It is used in Social Media where instant messaging is available. So, option (a) is not correct option.
  • Option (b) text messaging the technology is the technology in which the text messages are sent over the mobile networks ( in case of text messaging in mobile phones ) or over the internet ( emails, blogging etc). So, option (b) is not correct option.
  • Option (d) DES is not a short range wireless technology. So, option (d) is not correct.
  • Option (c) NFC is correct option.
3 0
2 years ago
Other questions:
  • What are the 6 external parts of a computer
    14·1 answer
  • Peripherals can be used to input information. True False
    6·2 answers
  • Creating calendar events prevents individuals from being able to schedule a time to collaborate.
    11·1 answer
  • ___ is a career discipline focusing on helping companies use computer technology effectively.
    12·1 answer
  • Write a sentence about a mineral you use and how you use it
    12·1 answer
  • What category of sensory receptors are sensitive to touch sound and motion?
    10·1 answer
  • The requester of sensitive information should not receive access just because of his or her clearance, position, or rank. The re
    15·1 answer
  • 2 Write<br>a program to and area of<br>4<br>walls. A = 2h (l+b)​
    6·1 answer
  • In regard to segmentation, all of the following are examples of a customer's behavior or relationship with a product EXCEPT: a)
    14·1 answer
  • Assume the name of your data frame is flavors_df. What code chunk lets you review the structure of the data frame?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!