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 ___ is a mobile device that typically ranges from seven to ten inches in size.
Ber [7]

A tablet computer, or commonly known as tablet,  is a mobile device that typically ranges from seven to ten inches in size. It has mobile operating system and LCD touchscreen display processing circuitry. The touchscreen display is operated by  finger. The tablet has many all of the functionalities of a computer, but not all of them.


3 0
4 years ago
Match each of the following steps of SDLC development to its position in the development process.
Arisa [49]

Answer:

Step One - problem/opportunity identification  (V)

Step Two - Analysis (III)

Step Three - Design (II)

Step Four - Development (I)

Step Five - Testing and Installation (IV)

Explanation:

In the field of software development, or systems engineering, SDLC which refers to software development cycle refers to a systematic way of building software applications, it shows unique stages with the outcome of each stage dependent on the previous, step has a unique task which range from the planning, analysis, development, testing and installation of the information system.

5 0
4 years ago
how to get into harvard stanford mit ivy league guaranteed upper middle class need aid 9th grade, computer science major have no
Murrr4er [49]

Answer:

Colleges care a lot more about your math skills than computer stuff, even for computer science. Make sure you still do some computer science stuff (esp. if it's extracurricular) but focus on improving your math.

8 0
3 years ago
A DNS server on your client's network is receiving a large number of DNS queries from what appears to be a workstation on their
drek231 [11]

Answer:

The answer is reflective DNS attack

Explanation:

Reflective DNS Attack is used in many distributed DDoS attacks to knock down an internet pipe. The attack is divided in two stages: first  the attacker sends lots of requests to one  or more legitimate DNS servers  while using spoofed source IP of the target person, and then, in the second stage, the DNS server receiving the semi-legitimate requests replies to the spoofed IP, thereby unknowingly lauching an attack on the target computer with responses to requests never sent by the victim.

4 0
4 years ago
How to send a message to another channel with an emoji slack
Advocard [28]

Answer: Tap and hold the message you'd like to share and select Share message. Tap the #channel name and choose where you'd like to share the message. Add an optional note, if you'd like. Tap the paper plane icon to share.

Explanation:

7 0
3 years ago
Other questions:
  • You are starting a spreadsheet, and you would like 500 to appear in cell C3. You should _____.
    11·2 answers
  • How many unique ip addresses can be made in a fixed-length ip address system using 6 bits?
    8·1 answer
  • simpley convert the code below to assembly languageYour proof-of-study task is to hand-compile the code below into an assembly l
    11·1 answer
  • You are seeking a way to store computer files so you have backup copies anywhere you go.? Which one of the secondary storage typ
    11·1 answer
  • Any one have a snnaap chhhaatt if so i need help with something n there
    15·2 answers
  • Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. T
    11·1 answer
  • The programming interface for a legacy motor controller accepts commands as binary strings of variable lengths.
    15·1 answer
  • Which clue can be used to identify a chemical reaction as a combustion reaction?
    9·1 answer
  • Which of the following is not an operating system a) boss b) window xp c) linux d) bindux​
    15·1 answer
  • Need help completing this coding assignment.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!