Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

home / study / engineering / computer science / computer science questions and answers / 3. write a java program (ex3.java) to compare two strings

home / study / engineering / computer science / computer science questions and answers / 3. write a java program (ex3.java) to compare two strings a and b, determine whether a contains ...

Question: 3. Write a Java program (Ex3.java) to compare two strings A and B, determine whether A contains a...

3. Write a Java program (Ex3.java) to compare two strings A and B, determine whether A contains all of the characters in B. The characters in string A and B are all Upper Case letters.

Example:

For A = "ABCD", B = "ACD", print "A contains B".

For A = "ABCD", B = "AABC", print "A doesn't contain B".

4. Write a Java program (Ex4.java) to find the contiguous subarray with smallest sum. Print the sum of the subarray.

Example:

For [1, -1, -2, 1], return -3.

5. Write a Java program (Ex5.java) to compute the number of trailing zeros in n factorial.

Example:

11! = 39916800, print 2

6. Write a program (Ex6.java) to play the game of "Guessing Number - 2 Players". Firstly, player one(P1) proposes a number N, the program generates a random number between 0 to N. Then, player two(P2) has 1 chance to guess the number. If P2 hits the number, P2 wins. Otherwise, P2 can either proposes a new number N' (N' <= N) and let the P1 guesses the new generated number, or doesn't propose any new number and let the P1 guesses the previous random number. Then, P1 has 1 chance to guess. If P1 hits the number, P1 wins. Otherwise, P1 can either proposes a new number N'' (N'' <= N (or N')) and let the P2 guesses the new generated number, or doesn't propose any new number and let the P2 guesses the previous random number. Keep repeating until one of players win the game.

Example:

(P1) - Welcome P1, please input a random seed:

(P1) - 5

(P2) - P2, please input your guess(0 - 5):

(P2) - 1

(P2) - Incorrect. Please select "ONE. Continue guessing; TWO. Generate a new number

(P2) - ONE

(P1) - P1, please input your guess(0 - 5):

(P1) - 2

(P1) - Incorrect. Please select "ONE. Continue guessing; TWO. Generate a new number

(P1) - TWO

(P1) - 4

(P2) - P2, please input your guess(0 - 4):

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions