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]
3 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]3 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
When creating a report,you can mske groups and subgroups by?​
Mnenie [13.5K]

Answer:

content of the report

Explanation:

  • you must clarify all things
  • the report would be clean and clear
7 0
2 years ago
A security administrator is reviewing the following information from a file that was found on a compromised host: Which of the f
Roman55 [17]

Answer:

C. Trojan

Explanation:

In Cybersecurity, vulnerability can be defined as any weakness, flaw or defect found in a software application or network and are exploitable by an attacker or hacker to gain an unauthorized access or privileges to sensitive data in a computer system.

This ultimately implies that, vulnerability in a network avail attackers or any threat agent the opportunity to leverage on the flaws, errors, weaknesses or defects found in order to compromise the security of the network.

In this scenario, a security administrator is reviewing the following information from a file that was found on a compromised host: "cat suspiciousfile.txt."

Some of the ways to prevent vulnerability in a network are;

1. Ensure you use a very strong password with complexity through the use of alphanumerics.

2. You should use a two-way authentication service.

3. You should use encrypting software applications or services.

8 0
3 years ago
You and a few friends are having a meal at a pizza restaurant, and the server has just given you the bill. Write a function that
cestrela7 [59]

Answer:

How to calculate the total cost of the meal

For bill inclusive of tax, cost1=cost*(1+tax percentage)

For bill inclusive of tax and tip, cost2=cost1*(1+tip percentage)

Meal cost =(pizza cost*(1+tax percentage))*(1+tip percentage)

Now how to calculate the cost per person

cost per person=meal cost/ number of people.

C language code to solve the above problem is given below with appropriate comments for explanation

Explanation:

#include<stdio.h>

float split_bill(int cost,float tax)

{

//Declaring number of people as int

int number;

//Prompting for number of people

printf("Enter number of people ");

scanf("%d",&number);

//Declaring tip percentage as float

float tip_percent;

//Prompting for tip percentage

printf("Enter tip percentage between 0 and 1 ");

scanf("%f",&tip_percent);

//Calculating total meal cost

float meal=(((float)cost)*(1+tax))*(1+tip_percent);

//Printing total cost of meal

printf("Total cost of meal: %0.2f ",meal);

//Calculating cost per person

float cost_per_person=meal/number;

//Returning cost per person to main function

return cost_per_person;

}

int main()

{

//Declaring pizza cost as int and tax percentage as float

int pizza_cost;

float tax_percent;

//Prompting user for pizza cost

printf("Enter billing amount of pizza ");

scanf("%d",&pizza_cost);

//Prompting user for tax percentage

printf("Enter tax percentage between 0 and 1 ");

scanf("%f",&tax_percent);

//Printing the cost per person by calling the function split_bill

printf("Total cost per person is: %0.2f ",split_bill(pizza_cost,tax_percent));

return 0;

}

8 0
3 years ago
What type of socket should be used with an air impact wrench
Vikentia [17]
<span>Black sockets should be used, but the color is not the reason why. Chrome sockets will cause splits to form in the socket walls pretty quickly, after only a few uses. But the black sockets are that color because they have gone through a process called Parkerizing that coats the surface of the socket in order to provide more resistance when being used and protect the socket against corrosion.</span>
3 0
3 years ago
PLEASE HELP ILL GIVE POINTD AND BRAINLIEST
Nastasia [14]

Answer:

I would have to say C.

Explanation:

Feel free to correct me if i'm wrong :)

Hope this helps

4 0
3 years ago
Other questions:
  • Write a program that asks the user to input four numbers (one at a time). After the four numbers have been supplied, it should t
    6·1 answer
  • Spreadsheet software creates a ____, composed of a grid of columns and rows
    6·1 answer
  • A user clicked an email link that led to a website than infected the workstation with a virus. The virus encrypted all the netwo
    10·1 answer
  • Using a single formatting _______ helps to make reading researched information easier; it lets the reader know what to expect.
    7·1 answer
  • PLEASE HELP!!!!!!!!!
    8·1 answer
  • D State Six Impact of ICT the society​
    7·1 answer
  • Which of the following statements about the relationship between hardware and software is true? a) Hardware can be present in in
    9·1 answer
  • 1: define about information system in computer?
    10·1 answer
  • We love silky. she is very honest join this by using conjunction ​
    11·2 answers
  • Types of Computer games​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!