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
JulijaS [17]
3 years ago
7

JAVAThe method longestStreak is intended to determine the longest substring of consecutive identical characters in the parameter

str and print the result.For example, the call longestStreak("CCAAAAATTT!") should print the result "A 5" because the longest substring of consecutive identical characters is "AAAAA".
Complete the method below. Your implementation should conform to the example above.
public static void longestStreak(String str)
Computers and Technology
1 answer:
Butoxors [25]3 years ago
5 0

Answer:

public static void longestStreak(String str){

       int maxCharacterCount = 0;

       char longestSubString = str.charAt(0);

       

       for(int i=0; i<str.length(); i++){

           

           int currentMaxCharacterCount = 1;

           

           for(int j=i+1; j<str.length(); j++){

               if(str.charAt(i) != str.charAt(j)){

                   break;

               }

               else {

                   currentMaxCharacterCount++;

               }

           }  

           if (currentMaxCharacterCount > maxCharacterCount) {

                   maxCharacterCount = currentMaxCharacterCount;

                   longestSubString = str.charAt(i);

           }

       }

       System.out.println(longestSubString + " "+ maxCharacterCount);

   }



Explanation:

Let's start from the top of the code and go all the way down.

- Two variables created; <em>maxCharacterCount</em> to count the longest character in the string, and <em>longestSubString</em> to save the current longest substring. Initially they are set to 0 and the first character of given string respectively.

- We need to check all the substrings to find longest one. That is why a <u>nested for loop</u> (for loop inside a for loop) is created.

- The first loop starts from the first character of the given string and goes until the end of the given string.

- Inside the first loop, <em>currentMaxCharacterCount</em> is created to hold the current value of the maximum character in the given string.

- The second loop starts from the second character of the string, and checks if the character is same as the one that is being checked by the first loop.

- If they are not same, then the loop stops.

- If they are the same characters, <em>currentMaxCharacterCount</em> is incremented by 1. (That means we may find our new longest substring)

* Reminder: When the <em>i</em> is equal to 0, <em>j </em>is increasing from 1 to given string length. When <em>i</em> is equal to 1 <em>j</em> is increasing from 2 to given string length and so on. This process repeats for all <em>i</em> and <em>j</em> values to find out the longest substring.

- If <em>currentMaxCharacterCount </em>is greater than<em> maxCharacterCount, </em>that means we have a new longest substring, and <em>maxCharacterCount </em>should be equal to this new substring's count.

- Then, to be able to check for the next possible longest substring, it should continue from the next iteration of the <em>i </em>(longestSubString = str.charAt(i);)

- Finally, when the loops are done checking, <em>longestSubString</em> and <em>maxCharacterCount</em> need to be printed.

You might be interested in
A computer record is used to store all the information about one transaction, but several such records must be used to store the
never [62]

Answer:

True

Explanation:

A single file can be used to record/ store all the information regarding a transaction because in a transaction there are less complexities. a  simple transaction involves an exchange/communication between a buyer and a seller which involves exchange in finances between the buyer and the seller.  

An employee can be involved in several activities like work activities and multiple transactions while a single inventory part record is different from an employee's record and  any other form of transaction. hence separate files have to be created for each of these activities.

To have an easy access to this information when needed a master file is created to store all the individual files.

7 0
3 years ago
Explain in details three security countermeasures you know.​
SpyIntel [72]

Answer:

The three options are:

1. Avoid sharing files and folders over the network without the permission of your administrators. You might fall in trouble otherwise.

2. Never share your credit card details with a third party through the internet. You can lose a lot of or all your money.

3. Always ensure that your password is strong enough or else your account can be hacked, And never share them with anybody.

Explanation:

Please check the answer.

4 0
3 years ago
The master system database stores a database template that is used as a blueprint when creating a new user database.
Novay_Z [31]
<span>An attribute in a relation of a database that serves as the primary key of another relation in the same database is called a</span>
6 0
3 years ago
In the SQL environment, a _____________ is a logical group of database objects – such as tables and indexes – that are related t
Paha777 [63]

Answer:Schema

Explanation: A schema is the group that contains objects of databases with views, index, triggers, tables etc features. The specific user can access schema who persist a certain username.The user is considered as the owner of the database and its element.

Schema is usually bound to have only single database.There are some schema that are already present in the system as the in-built schema .E.g.- sys, guest etc.

5 0
3 years ago
An employee’s total weekly pay equals the hourly wage multiplied by the total number of regular hours plus any overtime pay. Ove
Feliz [49]

Answer:

C++ programming language is used to implement this program using Dev C++. You can use any C++ compiler to run this program. The code and its explanation is given below in explanation section.

Explanation:

#include<iostream>

using namespace std;

int main()

{

int totalWeeklyPay;//total weekly pay  

int hourlyWage;// wages per hours

 

int totalRegularHour;// total regular hours worked

int totalOverTimeHour;// total over time hours worked

 

int weeklyTotalRegularPay;

int weeklyTotalOverTimePay;

 

cout<<"Enter Wage per hour: ";

 cin>>hourlyWage;

 if (hourlyWage<0)//if use enter negative value

  {

   cout<<"Please enter positive number number for wage per hour\n";

   cout<<"Enter Wage per hour: ";

     cin>>hourlyWage;

  }

cout<<"Enter total regular hour: ";

cin>>totalRegularHour;

if (totalRegularHour<0)//if user enter negative value

  {

   cout<<"Please enter positive total number of regular hour\n";

  cout<<"Enter total regular hour: ";

     cin>>totalRegularHour;

  }

cout<<"Enter total over time hour: ";

cin>>totalOverTimeHour;

 

 if(totalOverTimeHour<0)//if user enter negative value

   {

    cout<<"Please enter positive total number of over time hour\n";

  cout<<"Enter total over time hour: ";

  cin>>totalOverTimeHour;

     

     

 }

 

weeklyTotalRegularPay =hourlyWage*totalRegularHour;// total weekly regular hour pay

weeklyTotalOverTimePay=totalOverTimeHour*hourlyWage*1.5;// total weekly overtime pay

totalWeeklyPay=weeklyTotalRegularPay + weeklyTotalOverTimePay;//total weekly regular hour pay + // total weekly overtime pay

cout<<"Total Weekly Pay is: "<<totalWeeklyPay<<"$";//output

 

 

return 0;

 

}

3 0
3 years ago
Other questions:
  • Consider this scenario: A major government agency experiences a data breach. As a result, more than 100,000 personal records are
    7·2 answers
  • Web storage stores data in the browser in
    5·1 answer
  • Define the method object inc_num_kids() for personinfo. inc_num_kids increments the member data num_kids. sample output for the
    11·1 answer
  • What is commodity? explain
    14·1 answer
  • Create a function named first_a that uses a list comprehension. The function will take a single integer parameter n. Find every
    13·1 answer
  • When a client computer wants to connect to a service instance, what specific name type does it use to find the service?
    9·1 answer
  • In this lab, your task is to complete the following: Enable all of the necessary ports on each networking device that will allow
    9·1 answer
  • A sum of JS300 is divided in the ratio 2:3.
    9·1 answer
  • Your computer is taking longer than usual to open files and you notice that your hard drive light stays on longer than usual whi
    9·1 answer
  • RTOS stands for ______ Time Operating System.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!