1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
skad [1K]
2 years ago
8

1. Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the

user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal. (Ignore the case of the characters during comparison.) This is a sample run of your program: Enter·first·string:Have·yourself·a·merry·little·Christmas.↵ Enter·second·string:It's·beginning·to·look·a·lot·like·christmas.↵ Enter·starting·index·for·first·string:29·↵ Enter·starting·index·for·second·string:34·↵ Enter·number·of·characters·to·be·compared:9↵ true↵
Computers and Technology
1 answer:
likoan [24]2 years ago
8 0

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        System.out.print("Input first string: ");
  6.        String string1 = input.nextLine();
  7.        System.out.print("Input second string: ");
  8.        String string2 = input.nextLine();
  9.        System.out.print("Start index for first string: ");
  10.        int i1 = input.nextInt();
  11.        System.out.print("Start index for second string: ");
  12.        int i2 = input.nextInt();
  13.        System.out.print("Number of characters to be compared: ");
  14.        int n = input.nextInt();
  15.        if(string1.regionMatches(true, i1, string2, i2, n)){
  16.            System.out.println("The strings are equal.");
  17.        }
  18.        else{
  19.            System.out.println("The strings are not equal.");
  20.        }
  21.    }
  22. }

Explanation:

The solution code is written in Java.

Firstly create a Scanner object (Line 5).

Next, use the Scanner object and nextLine method to get user input for  string1 and string 2 (Line 7 - 11 )

Next, proceed to get the start index for first and second string using nextInt (Line 14 and Line 17) and followed with number of characters to be compared (Line 20).

Use the regionMatches method by passing all the input values as argument (Line 22) and if we pass the sample input we shall get the true and the program shall display the message "The strings are equal." (Line 22- 23)

You might be interested in
Why was unicode invented
Luden [163]
Uni code is short for universal code , it was created so that all countries could communicate together without the need for special encoding for each country
7 0
3 years ago
A(n) ____________ specifies a variable's name and data type.
Alla [95]
I think that would be a function
4 0
3 years ago
Read 2 more answers
Cuáles son las partes más importantes de una flor​
castortr0y [4]

Answer:

estas son

Explanation:

El cáliz. Está formado por los sépalos, que son un conjunto de hojas verdes en la base de la flor.

La corola. Está formada por los pétalos que son hojas coloreadas en el interior de los sépalos.

Los estambres. Son los órganos masculinos de la flor. ...

El pistilo. Es el órgano femenino de la flor.

7 0
3 years ago
Is there actually a difference between left and right twix
olga2289 [7]
One has more caramel and one has more cookie
6 0
2 years ago
please write out an accurate code for the question below also please explain or I'll report you ( Thanks :) )
leva [86]

Answer: hmmmm i feel like u have to move the thingy thats shooting that light down 1 unit so it can move the planet.

Explanation: moving it down 1 unit will put it at the perfect angle to push the planet. :/

6 0
1 year ago
Read 2 more answers
Other questions:
  • Which sparkline type is best for displaying trends in data changes over time?
    11·1 answer
  • Philip is thinking about customizing his motorcycle. A paint job, saddlebags, and a radio would cost $600. His motorcycle is old
    15·2 answers
  • in java Write a program with total change amount in pennies as an integer input, and output the change using the fewest coins, o
    13·1 answer
  • Who developed the first triage-like system for Napoleon's ar
    15·1 answer
  • If not cleared out, log files can eventually consume a large amount of data, sometimes filling a drive to its capacity. If the l
    10·2 answers
  • I need to calculate the % of Grand Total on Microsoft Excel, but can't for the life of me remember how to do that. Help would be
    8·1 answer
  • 3. In 1989, the first handheld console was released by _____ and it was called ________.
    13·1 answer
  • WILL MARK BRAINLIEST!!!!!!!!!!!
    6·2 answers
  • How will the health care professions be affected by all the computerized and technical advances concerning disabilities?
    9·1 answer
  • How do people decide their ethical behavior
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!