The loop below is intended to collect all characters that occur more than once in a given string. When you try it out with a string such as “Mississippi”, you will note that that letters that occur three or more times are collected more than once. Modify the loop so that each repeated letter is collected exactly once. For example, when s is “Mississippi”, result should be “si” and not “sissii” Only allowed to edit code in the /* Your code goes here */ portion. Thanks for the help!

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
The loop below is intended to collect all characters that occur more than once in a given string. When you try it out with a string such as “Mississippi”, you will note that that letters that occur three or more times are collected more than once. Modify the loop so that each repeated letter is collected exactly once. For example, when s is “Mississippi”, result should be “si” and not “sissii” Only allowed to edit code in the /* Your code goes here */ portion. Thanks for the help!
O I G DoLoop.java X
SentinelDemo.java ×
DuplicatedCharacters.java x
50 -/ldeaProjects 1
imprt java.util.Scanner;
3
public class DuplicatedCharacters
4
Compare2
5 >
public static void main(String[] args)
DoLoop
6.
{
Doublelnvestment2
DuplicatedCharacte
BElevatorSimulation2
C Errort
GError2
GError3
G HelloPrinter
G InvestmentTable
G PrintDemo
G ReciprocalSum
G SentinelDemo
G Shipping
G TaxCalculator
G Volume1
f. csC 1350.lml
Scanner in = new Scanner (System.in);
String s = in.next();
7
8
9
String rest = s;
10
String result = "";
11
int i = 0;
12
while (rest.length() > 0)
13
14
/*
15
Follow this outline:
16
String first = rest.substring(0, 1);
rest = rest.substring(1);
if (rest.contains(first))
17
18
19
{
External Libraries
20
result = result + first;
Scratches and Consoles 21
}
22
*/
23
24
/* Your code goes here */
25
26
}
27
System.out.println(result);
28
29
Q Event Log
2 Terminal
A Bulld
E TODO
O Problems
Debug
29:2 LF UTF-8 4 spaces 2
Run
All files are up-to-date (29 minutes ago)
IJ
tv
MacBook Pro
(
&
%D
delete
* 00
aunjanas
Transcribed Image Text:O I G DoLoop.java X SentinelDemo.java × DuplicatedCharacters.java x 50 -/ldeaProjects 1 imprt java.util.Scanner; 3 public class DuplicatedCharacters 4 Compare2 5 > public static void main(String[] args) DoLoop 6. { Doublelnvestment2 DuplicatedCharacte BElevatorSimulation2 C Errort GError2 GError3 G HelloPrinter G InvestmentTable G PrintDemo G ReciprocalSum G SentinelDemo G Shipping G TaxCalculator G Volume1 f. csC 1350.lml Scanner in = new Scanner (System.in); String s = in.next(); 7 8 9 String rest = s; 10 String result = ""; 11 int i = 0; 12 while (rest.length() > 0) 13 14 /* 15 Follow this outline: 16 String first = rest.substring(0, 1); rest = rest.substring(1); if (rest.contains(first)) 17 18 19 { External Libraries 20 result = result + first; Scratches and Consoles 21 } 22 */ 23 24 /* Your code goes here */ 25 26 } 27 System.out.println(result); 28 29 Q Event Log 2 Terminal A Bulld E TODO O Problems Debug 29:2 LF UTF-8 4 spaces 2 Run All files are up-to-date (29 minutes ago) IJ tv MacBook Pro ( & %D delete * 00 aunjanas
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY