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
The inflationary gap occurs when you obtain no increase in output, but only an increase in the Average Price Level from an incre
Katarina [22]
<span>B. Second phase of the Keynesian LRAS Curve.</span>
8 0
2 years ago
How does abstraction make programming languages easier to use
alexgriva [62]

Abstraction make programming languages easier to use as  It eliminates the need for codes to be automated.

<h3>How does abstraction make programming languages easier to implement?</h3>

Data abstraction is known to be a tool that helps a person to change a complex data structure into simple ones which can be used easily.

Note that Abstraction make programming languages easier to use as  It eliminates the need for codes to be automated.

Learn more about abstraction from

brainly.com/question/7994244

#SPJ1

6 0
1 year ago
Wi-Fi Protected Access (WPA) fixes critical vulnerabilities in the earlier wired equivalent privacy (WEP) standard. Understandin
Mars2501 [29]

Since Wi-Fi Protected Access (WPA) fixes critical vulnerabilities in the earlier wired equivalent privacy (WEP) standard, the attacks that is related to encrypted wireless packets is option A: IV attacks.

<h3>Describe an IV attack.</h3>

A wireless network attack is called an initialization vector (IV) attack. During transmission, it alters the IV of an encrypted wireless packet. One packet's plaintext can be utilized by an attacker to calculate the RC4 key stream produced by the IV employed.

Note that A binary vector used to initialize the encryption process for a plaintext block sequence in order to boost security by adding more cryptographic variance and to synchronize cryptographic hardware. The initialization vector is not required to be kept secret.

Learn more about Wi-Fi Protected Access  from

brainly.com/question/13068630
#SPJ1

See full question below

Wi-Fi Protected Access (WPA) fixes critical vulnerabilities in the earlier wired equivalent privacy (WEP) standard. Understanding that WPA uses a combination of an RC4 stream cipher and Temporal Key Integrity Protocol (TKIP), this makes a wireless access point NOT vulnerable to which of the following attacks when related to encrypted wireless packets?

IV attacks

Malware

Ransoware

5 0
1 year ago
A customer dictates instruction on how to transcribe audio. Do you have to transcribe the instruction word for word?
Ostrovityanka [42]

Answer:

No

Explanation:

4 0
2 years ago
Technology can help governments handle economic emergencies, such as the reliance on automation. Crop and resource shortages. Th
uranmaximum [27]

Answer

Technology can help government handle economic emergencies such as crop and resource shortages.

Explanation

The government can address the concerns of food shortages and water scarcity through embracing new technology interventions to increase farm yields and mitigate the impacts of water shortages. Through crop protection methods, weeds and pest can be controlled. Drip irrigation technology applies water directly to the roots of crops to facilitate high crop production. Other technologies to apply can include organic agriculture and integrated soil fertility management.



3 0
2 years ago
Read 2 more answers
Other questions:
  • What are the main differences between a workgroup and a domain?
    14·2 answers
  • How many unique ip addresses can be made in a fixed-length ip address system using 6 bits?
    8·1 answer
  • You can use the bash shell to redirect standard output or standard error from the terminal screen using the ____ shell metachara
    15·1 answer
  • To quit Word, click the Restore button on the right side of the title bar. <br> True <br> False
    6·1 answer
  • What is the aperture and how does it impact sunrise/sunset photos? What is generally considered an ideal aperture for sunrise/su
    5·2 answers
  • Please check my answer! (Java)
    7·1 answer
  • What is the square root of 1600 and 36 ?​
    6·1 answer
  • Write a Python program to find whether a given number (accept from the user) is positive
    11·1 answer
  • Would my phone still work if I snapped it in half?
    8·2 answers
  • 12. Why is it so important to pay attention to your digital reputation?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!