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
Student creates a Raptor program and uses the File Input and Output method to find the average of 5 test scores stored in a text
masya89 [10]

Answer:

The question was solved using an algorithm later translated to a flow chart that adds five scores giving the sum and calculating the average.

Explanation:

4 0
2 years ago
Define Turbo C++ and how is the use of Turbo C++.?
anyanavicka [17]

Answer:

Turbo C++ is a Compiler and Integrated development Environment (IDE) and Computer language

Explanation:

  1. Turbo C++ is a IDE which is used for writing the programs.
  2. This editor is used to create the source file, compile and run the source file and then execute it

6 0
2 years ago
Which ribbon tab is not a default in Outlook 2016's main interface?
IRISSAK [1]

Answer:

view

Explanation:

i just know it

8 0
2 years ago
Read 2 more answers
Determina la cilindrada total Vt en un motor de 4 cilindres de 83,6 mm de diàmetre per 91 mm de cursa.
insens350 [35]

Answer:

La cilindrada total del motor es de 1997,025 centímetros cúbicos.

Explanation:

Para determinar la cilindrada total Vt en un motor de 4 cilindros de 83,6 mm de diámetro por 91 mm de carrera se debe realizar el siguiente cálculo, sabiendo que para calcular la cilindrada de un motor se debe utilizar la fórmula ((Pi x Diámetro^2)/4) x Carrera x Número de cilindros = X:

((3.14 x 83.6^2)/4) x 91 x 4 = X

((3.14 x 6,988.96)/4) x 364 = X

(21,945.3344 / 4) x 364 = X

5,486.3336 x 364 = X

1,997,025.4304 = X

1 milímetro cúbico = 0.001 centímetro cúbico

1,997,025.4304 milímetros cúbicos = 1997.0254304000005 centímetros cúbicos

Por lo tanto, la cilindrada total del motor es de 1997,025 centímetros cúbicos.

3 0
2 years ago
Is a MODEM required for Internet Connectivity ?<br> Yes<br> No
Pie

Answer:

you can connect to the wifi on your device it will say you are connected but the wifi will not be connected to the internet so you will be able to do nothing on it without the modem

Explanation:

4 0
2 years ago
Read 2 more answers
Other questions:
  • Which keyboard feature is a form feed character?
    14·1 answer
  • Press the _______ key to move to the next cell in a row.
    12·2 answers
  • Is a network where connected devices are located within the same building.
    5·2 answers
  • Which operating system is a version of Linux?​
    13·1 answer
  • What is the square root of 1600 and 36 ?​
    6·1 answer
  • Nonverbal communication includes _____.
    9·2 answers
  • Write the definition of a function named fscopy. This function can be safely passed two fstream objects, one opened for reading,
    11·1 answer
  • How does it transform your ways of socializing
    11·1 answer
  • Please help me in this question​
    7·2 answers
  • From which os did windows xp evolve?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!