Show the output of the following code:
public class Test {
public static void main(String[] args) {
System.out.println(“Hi, ABC, good”.matches(“ABC ”));
System.out.println(“Hi, ABC, good”.matches(“.*ABC.*”));
System.out.println(“A,B;C”.rep1aceAll(“, ;”#”));
System.out.println(“A,B;C”.replaceAll(“[, ;]”, “#”));
String[] tokens = “A,B;C”.split(“[,;]”);
for (int i = 0; i < tokens.length; i++)
System.out.print(tokens[i] + “ ”);
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Starting Out with C++: Early Objects (9th Edition)
Concepts Of Programming Languages
Starting Out with Java: Early Objects (6th Edition)
- Write a test class to test the methods length, charAt, substring, and indexOfin the java.lang.String class.arrow_forwardpublic class main { public static void main(String [] args) { Dog dog1=new Dog(“Spark”,2),dog2=new Dog(“Sammy”,3); swap(dog1, dog2); System.out.println(“dog1 is ”+ dog1); System.out.println(“dog2 is ”+ dog2); } public static void swap(Dog a, Dog b) { String nameA = a.getName(); String nameB = b.getName(); a.setName(nameB); b.setName(nameA); } What is the output of the main()?arrow_forwardWrite the Java program: Make sure to have proper code indentation. Code: class Main { public static void main(String[] args) { Tile t1, t2, t3, t4, t5; int totalValue; t1 = new Tile('H', 4); t2 = new Tile('E', 1); t3 = new Tile('L', 1); t4 = new Tile('L', 1); t5 = new Tile('O', 1); totalValue = t1.getValue() + t2.getValue() + t3.getValue() + t4.getValue() + t5.getValue(); System.out.print("The word "); System.out.print(t1.getLetter()); System.out.print(t2.getLetter()); System.out.print(t3.getLetter()); System.out.print(t4.getLetter()); System.out.print(t5.getLetter()); System.out.println(" is worth " + totalValue + " points"); if(t4.equals(t3)) { System.out.print("It has two of these: "); System.out.println(t4); } else { System.out.print("Error: " + t3.toString() + " and ");System.out.println(t4.toString() + " aren't equal."); } }} /* SAMPLE OUTPUT The word HELLO is worth 8 pointsIt…arrow_forward
- how would you change the test method of the palindrome class so that it considerer all character, not just letters? please identify the statements you would change, and how you would change them: public class Palindrome { public static boolean test(String candidate) // Returns true if candidate is a palindrome, false otherwise. { char ch; // current candidate character being processed int length; // length of candidate string char fromStack; // current character popped from stack char fromQueue; // current character dequeued from queue boolean stillPalindrome; // true if string might still be a palindrome StackInterface<Character> stack; // holds non blank string characters QueueInterface<Character> queue; // also holds non blank string characters // initialize variables and structures length = candidate.length(); stack = new ArrayBoundedStack<Character>(length);…arrow_forwardJAVA Program ASAP Please modify this program and take out the main method from the program so it passes the test cases in Hypergrade. I have provided the failed test cases. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.InputMismatchException;import java.util.Scanner;public class FileSorting { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Please enter the file name or type QUIT to exit:"); String fileName = scanner.nextLine(); if (fileName.equalsIgnoreCase("QUIT")) { break; } try { ArrayList<String> lines = readFile(fileName); if (lines.isEmpty()) { System.out.println("File " + fileName + " is empty."); } else { performSorting(lines);…arrow_forwardChange Java code below so that it outputs a 9x9 board and not a 3x3 board. import java.util.*; public class Tic_Tac_Toe{ static String[] board;static String turn;static String checkWinner(){for (int a = 0; a < 8; a++) {String line = null; switch (a) {case 0:line = board[0] + board[1] + board[2];break;case 1:line = board[3] + board[4] + board[5];break;case 2:line = board[6] + board[7] + board[8];break;case 3:line = board[0] + board[3] + board[6];break;case 4:line = board[1] + board[4] + board[7];break;case 5:line = board[2] + board[5] + board[8];break;case 6:line = board[0] + board[4] + board[8];break;case 7:line = board[2] + board[4] + board[6];break;}//For X winnerif (line.equals("XXX")) {return "X";} // For O winnerelse if (line.equals("OOO")) {return "O";}} for (int a = 0; a < 9; a++) {if (Arrays.asList(board).contains(String.valueOf(a + 1))) {break;}else if (a == 8) {return "draw";}} // To enter the X Or O at the exact place on board.System.out.println(turn + "'s turn; enter…arrow_forward
- Identify the method stub in the following code: public class VoltageCalc { private int inCurrent; private double inResistance; public void setValues(int i, double r) { inCurrent = i; inResistance = r; } public int getVoltage() { System.out.println("FIXME: Calc Voltage");return 0;} public static void main(String [] args) { VoltageCalc myCircuit = new VoltageCalc(); myCircuit.setValues(4, 3.15); } } Group of answer choices public void setValues(int i, double r) {...} public class VoltageCalc {...} public int getVoltage() {...} public static void main(String [] args) {...} Nextarrow_forwardAnswer with a given JAVA question below. Consider the following code: public class Quiz{ public String name; public double totalPoints; public String getName() { return this.name; } public double getTotalPoints() { return this.totalPoints; } } Based on the Java code, explain where information hiding is being violated, why it is considered a violation, and how a programmer should fix the violation.arrow_forwardimport java.util.Scanner; public class sample { public static double totalProfit = 0.00; public static double totalTax = 0.00; static void ProfitandTax(double S , double E , int count){ double Tax = (S * 30.00)/100.00; /* Tax is 30% of sales and it is also considered as expenses of business so this will be a type of expenses */ double totalExpense = (E + Tax ); double Profit = (S - totalExpense); // Profit is given by sales subtracted by expenses System.out.println("Profit for " + count + " branch is : " + Profit); System.out.println("Tax for " + count + " branch is : " + Tax); totalProfit += Profit; totalTax += Tax; } public static void main(String[] args){ Scanner sc = new Scanner(http://System.in); System.out.println("Enter no of branches you have "); int k = sc.nextInt(); for(int i=0;i< k ;i++){ System.out.println("Enter Sales for " + (i+1 )+ " branch " ); double S = sc.nextDouble(); System.out.println("Enter Expenses for " + (i+1) + " branch " ); double E = sc.nextDouble();…arrow_forward
- Java Program Fix this Rock, Paper and scissor program so I can upload it to Hypergrade and it can pass all the test cases. Here is the program: import java.util.Random;import java.util.Scanner;public class RockPaperScissors { public static void main(String[] args) { if (args.length != 1) { System.out.println("Please provide a seed as a command line argument."); return; } long seed = Long.parseLong(args[0]); Random random = new Random(seed); Scanner scanner = new Scanner(System.in); System.out.println("Enter 1 for rock, 2 for paper, and 3 for scissors."); do { int computerChoice = random.nextInt(3); int userChoice = getUserChoice(scanner); if (userChoice == -1) { continue; } System.out.println("Your choice: " + choiceToString(userChoice) + ". Computer choice: " + choiceToString(computerChoice) + "."); int result =…arrow_forward3. What will be the output of the following Java Program? class Test { public static void main(String args[]) { int arr[] = new int[2]; System.out.println(arr[0]); System.out.println(arr[1]); }}arrow_forwardpublic class Myclass{ private static int count=0; private int x; //} public Myclass(int i) { x=i; } public void incrementCount(){ count++; } public void printX(){ System.out.println("Value of x : "+ x); } public static void printCount(){ System.out.println("Value of Count : "+count); } } public class MyclassDemo{public static void main(String[] args){ Myclass myObject1 = new Myclass(5); Myclass myObject2 = new Myclass(7); }} what is the outputof the following java code? (Assume that following statements are written inside main) g) my Object1.setX(14); output: h) myObject1.incrementCount(); output: i) myObject1.printX(); output: j) myObject1.printCount(); output: k) myObject2.printCount(); output:arrow_forward
- 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