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
Gnom [1K]
3 years ago
8

Lucky Sevens. Given a whole number, compute and display how many digits in the number are 7s. For example, the number of 7s in 3

482 is 0, while the number of 7s in 372771 is 3. Note: whole numbers are non-negative integers starting at zero {0, 1, 2, 3, 4, …}
Computers and Technology
1 answer:
Sveta_85 [38]3 years ago
6 0

Answer:

Code is in both c++ and java

Explanation:

C++ Code

#include<iostream>  

#include <sstream>  // for string streams  

#include <string>  // for string  

using namespace std;  

int main()  

{  

   int num;  

   cout<<"Enter Non-Negative number :";

  cin>> num;

   // declaring output string stream  

   ostringstream str1;  

   // Sending a number as a stream into output  

   // string  

   str1 << num;  

   // the str() coverts number into string  

   string geek = str1.str();  

   int count =0;

  for (int i = 0; i < geek.size(); i++){

    if(geek[i]=='7'){

     count++;  

 }

}

   // Displaying the string  

   cout << "the number of 7s in "<<num<< "is"<<count;

 

   return 0;  

}

Java Code

import java.util.Scanner;

public class LuckySeven{

   public static void main(String[] args){

       Scanner scanner = new Scanner(System.in);

       System.out.print("Enter Number :");

       int number = scanner.nextInt();

       String numberString = number+"";

       int count =numberString.length()- numberString.replaceAll("7","").length();

       System.out.println("Number of 7's in "+numberString+" are "+count);

   }

}

Code Explanation

First we need to take integer number as input from user.

As we need to iterate through all of the digits in number, that's why we need to convert integer to string as string is an array of character so we will iterate through number array and match the total count of 7 on every index.

At the end we will display the total count of 7 in number.

Sample Output

Case 1

Enter Non-Negative number :3482

the number of 7s in 3482 is 0

Case 2

Enter Non-Negative number :372771

the number of 7s in 372771 is 3

You might be interested in
A __________ attack is a bot attack on a computer system or network that causes a loss of service to users.
PSYCHO15rus [73]

Answer:

DDos or Distributed Denial Of Service Attack

Explanation:

:)

4 0
1 year ago
Which term describes an event where a person who does not have the required clearance or access caveats comes into possession of
notka56 [123]

Answer:

The answer is "compromise"

Explanation:

In computer science, the comprised system is used to describe as any technological resource, that has been negatively affected by an untrustworthy source for nondisclosure, integrity or accessibility either deliberately or inadvertently.

  • In this, the mechanical interaction from the unauthorized source or technological progress can result in compromise.
  • This helps you and the partner to meet each other's interests by taking into consideration both the positions and the solution to the main problem.

4 0
3 years ago
Read 2 more answers
Access time is:________.
worty [1.4K]

Answer:

B) the time it takes for the required sector to position itself under the read/write head.

Explanation:

In Computer science, Access time is the time it takes for the required sector to position itself under the read/write head. It is usually measured in milliseconds.

It is the speed of the storage device.

5 0
3 years ago
Assume the method doSomething has been defined as follows: public static void doSomething (int[] values, int p1, int p2) { int t
Dmitriy789 [7]

Answer:

The answer to this question is option "b".

Explanation:

In the method definition, we perform swapping. To perform swapping we define a variable "temp" that swap values of variable p1 and p2 and store in array that is "values". and other options are not correct that can be defined as:

  • In option a, It does not insert any new value in array because we do not pass any value in function.
  • In option c, The function does not copy and assign a value in a new array because in this function we not assign any new array.  
  • In option d, It is incorrect because it can not move an element into high index position.
8 0
2 years ago
What is a grant cycle?
Lina20 [59]

Answer:

The grant lifecycle refers to the entire process a grant goes through—from creating the opportunity through implementation and ending with the closeout.

Explanation:

... The grant lifecycle is comprised of three distinct phases: Pre-Award, Award, and Post Award. Hope that this helps you and have a great day :)

5 0
2 years ago
Read 2 more answers
Other questions:
  • The support group at Universal Containers wants agents to capture different information for product support and inquiry cases. I
    14·1 answer
  • What bus carries a status signal back to the CPU?
    14·1 answer
  • Interest rate risks would be most relevant to what purchase?
    7·2 answers
  • The _________ unit, within the CPU, interprets software instructions and literally tells the other hardware devices what to do,
    5·1 answer
  • write a c++ program that writes weather data from a file wx_data.txt to a file wx_summary for everyday of the year. also add min
    15·1 answer
  • You want to calculate a bonus if the sold price was at least equal to the listing price, and if the house sold within 30 days af
    6·1 answer
  • Something I should look for when trying to decide if a source is credible is the publication's ....
    10·1 answer
  • Re:
    15·1 answer
  • Firestick optimizing system storage and applications
    14·1 answer
  • 1. The letters that appear after the dot after a file name are called the:
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!