Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
6. For each of the following examples, what is the output? Example
String s1 = "Welcome to Java";
String s2 = new String("Welcome to Java");
String s3 = "Welcome to Java";
String s4 = new String("Welcome to Java");
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s2 == s4);
String s1 = "welcome to java";
String s2 = s1.replace('a', 'A');
System.out.println(s2);
String s3 = s1.replaceAll("java", "JAVA");
System.out.println(s3);
String s4 = s1.replaceFirst("a", "A");
System.out.println(s4);
Output
Page 2 of 3
Lab 2 - Preparation Questions
ITDR2104 - Programming
String s1 = "welcome to Java";
String s2 = "java";
String s3 = "Java";
String s4 = "Java is fun"; System.out.println(s1.matches("Java.*")); System.out.println(s2.matches("Java.*")); System.out.println(s3.matches("Java.*")); System.out.println(s4.matches("Java.*"));
String s1 = "welcome to Java";
String[] tokens1 = s1.split(" ");
for (String token : tokens1) {
System.out.println("[" + token + "]");
}
String[] tokens2 = s1.split(" ", 0);
for (String token : tokens2) {
System.out.println("[" + token + "]");
}
String[] tokens3 = s1.split(" ", 2);
for (String token : tokens3) {
System.out.println("[" + token + "]");
}
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 4 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
- 8. What will the following print out? int num = 7; System.out.println("Song titles with numbers include: "); switch (num) { case 12: System.out.println ("12 days of Christmas"); case 99: System.out.println("99 bottles of beer on the wall"); System.out.println ("99 Luftballons"); case 7: System.out.println ("7 Chinese Brothers"); case 50: System.out.println("50 Mission Cap"); default: System.out.println("If I had a million dollars"); } А. Song titles with numbers include: 7 Chinese Brothers 50 Mission Cap If I had a million dollars В. Song titles with numbers include: 7 Chinese Brothers С. Song titles with numbers include: 12 Days of Christmas 99 bottles of beer on the wall 99 LuftBallons 7 Chinese Brothers D. Song titles with numbers include:arrow_forwardusing System; class TicTacToe { Console.WriteLine("Do you want be X or O: "); Console.Write("Press 1 for 'X' or Press 2 for 'O'\n"); choice = int.Parse(Console.ReadLine()); if(choice==1) staticint player = 1 staticint choice; { staticvoid Print(char[] board) { 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(); } staticvoid Main(string[] args) { char[] board = newchar[9]; for (int i = 0; i < 9; i = i + 1) { board[i] = ' '; } 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); } } } How can this program be fixed to ask the user "It is your turn to place an X. Where would you like to place it?"arrow_forwardInteger userValue is read from input. Assume userValue is greater than 1000 and less than 99999. Assign tensDigit with userValue's tens place value. Ex: If the input is 15876, then the output is: The value in the tens place is: 7 2 3 public class ValueFinder { 4 5 6 7 8 9 10 11 12 13 GHE 14 15 16} public static void main(String[] args) { new Scanner(System.in); } Scanner scnr int userValue; int tensDigit; int tempVal; userValue = scnr.nextInt(); Your code goes here */ 11 System.out.println("The value in the tens place is: + tensDigit);arrow_forward
- using System; class Program { publicstaticvoid Main(string[] args) { int number = 1000000; while (number >= 1) { Console.WriteLine(number); number = number / 2; { Console.WriteLine(number); if(number==3){ Console.WriteLine("I found 3!"); } } } } } This code is written in C# and it starts with 1,000,000 and it divides it in half until the last number is 0. Something went wrong with the program and it prints the same number twice. how can that be fixed so it only prints out the numbers once instead of duplicating them before moving on the next? sorry if that doesn't make much sense!arrow_forwardFind and fix any logic and syntax errors. Program runs and produce the following output. Tips are The tip should be at least 7.5 The tip should be at least 2.99 // This class calculates a waitperson's tip as 15% of the bill// public class DebugThree1 { public static void main(String args[]) { double myCheck = 50.00; double yourCheck = 19.95; System.out.println("Tips are"); calcTip(myCheck); calcTip(yourCheck); } public void calcTip(double bill) { final double RATE = 0.15; double tip; tip = check * RATE; System.out.println("The tip should be at least " + tip); } }arrow_forwardJAVA Write a substring expression to extract “Exam” from the following String. String str= “Final Exam”;arrow_forward
- tranlate source program in the picture into quadruplesarrow_forwardIn Java: Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or 1995! the output is: no Hint: Use a loop and the Character.isDigit() function.arrow_forwardIn Java: String Word1="The Kean", Word2="University"; String print2=Word1.substring(4,8);arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education