Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 21.2, Problem 21.2.7CP
Program Plan Intro

Program:

//import util package

import java.util.*;

//class definition

public class Test {

// main method

public static void main(String[] args) {

//Create a new Set set1 ofLinkedHash Set type

LinkedHashSet<String> set1 = new LinkedHashSet<>();

/* add NewYork element into the set using the add() method */

set1.add("New York");

/*Create a new set set2 which equals set1 */

LinkedHashSet<String> set2 = set1;

//clone set1 and assign it a new set set2

LinkedHashSet<String> set3 =

(LinkedHashSet<String>)(set1.clone());

//add Atlanta to the set1

set1.add("Atlanta");

//print each set

System.out.println("set1 is " + set1);

System.out.println("set2 is " + set2);

System.out.println("set3 is " + set3);

/* Print each element present in set 1 using the ForEach() method */

set1.forEach(e -> System.out.print(e + " "));

}

}

Blurred answer
Students have asked these similar questions
using System; class Program { publicstaticvoid Main(string[] args) { int number = 1,i; while (number <= 88) { Console.WriteLine(number); number = number + 2; { Random r = new Random(); int[] randNo=newint[3]; for(i=0;i<3;i++) { randNo[i]= r.Next(1,88) Console.WriteLine("Random Number between 1 and 88 is "+randNo); } } } } }     how can this program be fixed to choose three random numbers in C# between 1-88 instead of just one random number?
// SuperMarket.java - This program creates a report that lists weekly hours worked  // by employees of a supermarket. The report lists total hours for  // each day of one week.  // Input:  Interactive // Output: Report.  import java.util.Scanner; public class SuperMarket {    public static void main(String args[])     {       // Declare variables.       final String HEAD1 = "WEEKLY HOURS WORKED";       final String DAY_FOOTER = "          Day Total ";  // Leading spaces are intentional.       final String SENTINEL = "done";     // Named constant for sentinel value.        double hoursWorked = 0;             // Current record hours.       String hoursWorkedString = "";      // String version of hours       String dayOfWeek;       // Current record day of week.       double hoursTotal = 0;           // Hours total for a day.       String prevDay = "";             // Previous day of week.       boolean done = false;            // loop control       Scanner input = new…
using System; class Program { publicstaticvoid Main(string[] args) { int number = 1; while (number <= 88) { Console.WriteLine(number); number = number + 2; } int[] randNo = newint[88]; Random r = new Random(); int i=0; while (number <= 88) { randNo[i] = number; number+=1; i+=1; } for (i = 0; i < 3; i++) { Console.WriteLine("Random Numbers between 1 and 88 are " + randNo[r.Next(1, 88)]); } } }     this code counts from 1-88 in odds and then selects three different random numbers. it keeps choosing 0 as a random number everytime. how can that be fixed?
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education