
Microsoft Visual C#
7th Edition
ISBN: 9781337102100
Author: Joyce, Farrell.
Publisher: Cengage Learning,
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
java
![•• 7. It is a common error to to accidentally repeat a word. Write a program that reads a sentence, a word at a time, and removes any adjacent duplicates. The sentence ends when you read a word that ends in a
period. The sentence will have at least two words.
RemoveDuplicateWords.java
1 import java.util.Scanner;
2
3 public class RemoveDuplicatewords
4 {
5
public static void main(String[] args)
Scanner in = new Scanner(System.in);
String word =
in.next();
10
boolean done =
false;
11
while (!done)
12
codecheck-bjlo-1e-04 19
String previous = in.next();
word = in.Hasnext();
if (word.endsWith("."))
{
word = in.next();
done = true;
}
if (compare.wordWith("."))
{
System.out.print(previous +
13
14
15
16
17
18
19
20
21
22
");
23
24
}
25
System.out.print (word + ".");
26
27 }
CodeCheck
Reset
Score: 0](https://content.bartleby.com/qna-images/question/7843148e-3437-49b9-8a58-49c07007b112/dbfd4dee-55ea-4b88-a153-52f92fdcfbfe/gql6m0u.png)
Transcribed Image Text:•• 7. It is a common error to to accidentally repeat a word. Write a program that reads a sentence, a word at a time, and removes any adjacent duplicates. The sentence ends when you read a word that ends in a
period. The sentence will have at least two words.
RemoveDuplicateWords.java
1 import java.util.Scanner;
2
3 public class RemoveDuplicatewords
4 {
5
public static void main(String[] args)
Scanner in = new Scanner(System.in);
String word =
in.next();
10
boolean done =
false;
11
while (!done)
12
codecheck-bjlo-1e-04 19
String previous = in.next();
word = in.Hasnext();
if (word.endsWith("."))
{
word = in.next();
done = true;
}
if (compare.wordWith("."))
{
System.out.print(previous +
13
14
15
16
17
18
19
20
21
22
");
23
24
}
25
System.out.print (word + ".");
26
27 }
CodeCheck
Reset
Score: 0
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- (Numerical) Write and test a function that returns the position of the largest and smallest values in an array of double-precision numbers.arrow_forward15. Write a program to implement and test the algorithm that you designed for Exercise 15 of Chapter 1. (You may assume that the value of . In your program, declare a named constant PI to store this value.)arrow_forward(File creation) Write a C++ program that creates an array containing the integer numbers 60, 40, 80, 90, 120, 150, 130, 160, 170, and 200. Your program should then write the data in the array to a text file. (Alternatively, you can create the file with a text editor.)arrow_forward
- (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays so that a customer’s record can be accessed randomly by account number. Create the file by entering five customer records, with each record consisting of an integer account number (starting with account number 1000), a first name (maximum of 10 characters), a last name (maximum of 15 characters), and a double-precision number for the account balance. After the file is created, write a C++ program that requests a user-input account number and displays the corresponding name and account balance from the file.arrow_forward(Electrical eng.) a. An engineer has constructed a two-dimensional array of real numbers with three rows and five columns. This array currently contains test voltages of an amplifier. Write a C++ program that interactively inputs 15 array values, and then determines the total number of voltages in these ranges: less than 60, greater than or equal to 60 and less than 70, greater than or equal to 70 and less than 80, greater than or equal to 80 and less than 90, and greater than or equal to 90. b. Entering 15 voltages each time the program written for Exercise 7a runs is cumbersome. What method could be used for initializing the array during the testing phase? c. How might the program you wrote for Exercise 7a be modified to include the case of no voltage being present? That is, what voltage could be used to indicate an invalid voltage, and how would your program have to be modified to exclude counting such a voltage?arrow_forwardMark the following statements as true or false. A double type is an example of a simple data type. (1) A one-dimensional array is an example of a structured data type. (1) The size of an array is determined at compile time. (1,6) Given the declaration: int list[10]; the statement: list[5] - list[3] * list[2]; updates the content of the fifth component of the array list. (2) If an array index goes out of bounds, the program always terminates in an error. (3) The only aggregate operations allowable on int arrays are the increment and decrement operations. (5) Arrays can be passed as parameters to a function either by value or by reference. (6) A function can return a value of type array. (6) In C++, some aggregate operations are allowed for strings. (11,12,13) The declaration: char name [16] = "John K. Miller"; declares name to be an array of 15 characters because the string "John K. Miller" has only 14 characters. (11) The declaration: char str = "Sunny Day"; declares str to be a string of an unspecified length. (11) As parameters, two-dimensional arrays are passed either by value or by reference. (15,16)arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning

Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage

Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning