Concept explainers
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 + " "));
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 21 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- Contoh Dalam pemrograman java: class Introduction { public static void main(String args[ ]) { byte x=50.5; System.out.println("Nilai dari variabel x= "+x)3; } ERROR MENGAPA???arrow_forwardJAVA PROGRAMFILL IN THE BLANKSarrow_forward// JAVA program to calculate the average score // import utility class for list collectionimport java.util.*; // class definitionpublic class Main{// main methodpublic static void main(String[] args) { // Variable declarationchar middle_initial;int id;double score1, score2, score3, average;String first_name, last_name, choice; // Scanner to read user inputsScanner sc = new Scanner(System.in); // integer counter to count number of studentsint counter = 0; // run a do-while loop until the user enters N or Nodo{// prompt user to enter first name, middle initial, and last nameSystem.out.print("Enter student's First Name:");first_name = sc.next();System.out.print("Enter student's Middle Initial:");middle_initial = sc.next().charAt(0);System.out.print("Enter student's Last Name:");last_name = sc.next(); // Add fullName of student in the Name listName.add(first_name + "." + middle_initial + "." + last_name); // enter idSystem.out.print("Enter student's Id:");id = sc.nextInt(); // add Id…arrow_forward
- package payroll2; // This program calculates an employee's take home pay. import javax.swing.JOptionPane; public class Payroll { private static double sum; private static double salary; private static double dependentDeduction; public static void main(String args[]) { { double salary; double numDependents; double dependentDeduction = salary * 0.025 * numDependents; double stateTax = salary * 0.065; double federalTax = salary * 0.28; double totalWithholding= stateTax + federalTax; double takeHomePay = salary - stateTax - federalTax + dependentDeduction; // Calculate state tax here. JOptionPane.showInputDialog("Enter Employee name: "); JOptionPane.showInputDialog("Enter Salary: ");//prompt…arrow_forward#include using namespace std; class Student { public: void setMarks(){ } double getAV(double a[]){ double sum=0; for(int i=0;i<7;i++) sum-sum+a[i]; return sum/7; double a[]={10, 20, 30, 40, 50, 60, 70); cout<arrow_forwardIn C++ QUESTION 14 class rectangleType { public: void setLengthWidth(double x, double y); //Sets the length = x; width = y; void print() const; //Output length and width double area(); //Calculate and return the area of the rectangle (length*width) double perimeter(); //Calculate and return the perimeter (length of outside boundary of the rectangle) private: double length; double width; }; Write the function definition for the function perimeterarrow_forwardusing System; class TicTacToe { staticint player = 1; staticint choice; staticvoid Print(char[] board) { staticvoid Main(string[] args) { Console.WriteLine(); Console.WriteLine($" {board[0]} | {board[1]} | {board[2]} "); Console.WriteLine($" {board[3]} | {board[4]} | {board[5]} "); Console.WriteLine($" {board[6]} | {board[7]} | {board[8]} "); Console.WriteLine(); char[] board = newchar[9]; for (int i = 0; i < 9; i = i + 1) { board[i] = ' '; if( board[i]== 'O') Console.Write("It is your turn to place an X"); } Print(board); board[4] = 'X'; Print(board); board[0] = 'O'; Print(board); board[3] = 'X'; Print(board); board[5] = 'O'; Print(board); board[6] = 'X'; Print(board); board[2] = 'O'; Print(board); } } } Hello, what can be added to this program to make it compile? just a small simple changearrow_forwardWhat does the following code print out? class Main { public static void main (String[] args) { int [] myArray = {3, 41, 7, 12, 9, 1, 15, 11, 17}; int someInt - myMethod (myArray) ; System.out.println (someInt); private static int myMethod (int [] arr) { int number = Integer.MIN VALUE; for (int i = 0; i 0) { number - arr[i]; } return number; O 41 17 11arrow_forward** IT'S A JAVA DEBUGGING PROBLEM! // Application looks up home price // for different floor plans // allows upper or lowercase data entry import java.util.*; public class DebugEight3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String entry; char[] floorPlans = {'A','B','C','a','b','c'} int[] pricesInThousands = {145, 190, 235}; char plan; int x, fp = 99; String prompt = "Please select a floor plan\n" + "Our floorPlanss are:\n" + "A - Augusta, a ranch\n" + "B - Brittany, a split level\n" + "C - Colonial, a two-story\n" + "Enter floorPlans letter"; System.out.println(prompt); entry = input.next(); plan = entry.charAt(1); for(x = 0; x < floorPlans.length; ++x) if(plan == floorPlans[x]) x = fp; if(fp = 99) System.out.println("Invalid floor plan code entered")); else { if(fp >= 3)…arrow_forwardIn C++ class rectangleType { public: void setLengthWidth(double x, double y); //Sets the length = x; width = y; void print() const; //Output length and width double area(); //Calculate and return the area of the rectangle (length*width) double perimeter(); //Calculate and return the perimeter (length of outside boundary of the rectangle) private: double length; double width; }; Declare an instance of rectangleType.arrow_forwardIn C++ class rectangleType { public: void setLengthWidth(double x, double y); //Sets the length = x; width = y; void print() const; //Output length and width double area(); //Calculate and return the area of the rectangle (length*width) double perimeter(); //Calculate and return the perimeter (length of outside boundary of the rectangle) private: double length; double width; }; Set the length of the rectangle to 24 and the width to 30.arrow_forwardIn C++ class rectangleType { public: void setLengthWidth(double x, double y); //Sets the length = x; width = y; void print() const; //Output length and width double area(); //Calculate and return the area of the rectangle (length*width) double perimeter(); //Calculate and return the perimeter (length of outside boundary of the rectangle) private: double length; double width; }; Print out the area of the rectangle.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education