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
1. Reference initials are always typed on a business letter.
solniwko [45]

Answer:

1. true 2.false 3.a 4.d 5.c 6.d 7. true 8.true 9.true 10.true

Explanation:

5 0
4 years ago
3.6 code practice (edhesive)
Pie

largest = int(input("Enter a number: "))

print("Largest: {}".format(largest))

i = 0

while i < 5:

   num = int(input("Enter a number: "))

   if num > largest:

       largest = num

   print("Largest: {}".format(largest))

   i += 1

I hope this helps!

4 0
3 years ago
Which command must you use at the command prompt to determine the names of the network interfaces (including the isatap interfac
spayn [35]

ipconfig /all is operate at the command prompt to specify the names of the network interfaces (including the isatap interfaces) on a windows 7 computer.

<h3>What is Network interfaces?</h3>

A network interface exists the network-specific software that communicates with the network-specific device driver and the IP layer to furnish the IP layer with a consistent interface to all network adapters that might be present. The network interface may direct to Network interface controller, a computer hardware element that connects a computer to a computer network Network interface device, a device that functions as the demarcation.

config exists a console application program of some computer operating systems that shows all current TCP/IP network configuration values and refreshes Dynamic Host Configuration Protocol and Domain Name System settings.

Hence, ipconfig /all is operate at the command prompt to specify the names of the network interfaces (including the isatap interfaces) on a windows 7 computer.

To learn more about Network interfaces refer to:

brainly.com/question/20689912

#SPJ4

3 0
2 years ago
Which loan type requires you to make loan payments while you’re attending school?
LUCKY_DIMON [66]
The answer is student loans
3 0
4 years ago
Read 2 more answers
What are the five types of alignment in Word?
Basile [38]
There are four types of alignment in word.
Left-aligned text
Right-aligned text
Center-aligned text
Justified text
6 0
3 years ago
Read 2 more answers
Other questions:
  • Complete the function ConvertToDecadesAndYears to convert totalYears to decades and years. Return decades and years using the Ti
    10·1 answer
  • How do you solve this.
    12·1 answer
  • Which database item would show details such as a customer’s name, their last purchase, and other details about a customer
    14·2 answers
  • What date does GTA 6 come out<br> A. 2020<br> B. 2019<br> C. 2021<br> D. 2022
    10·2 answers
  • Arrange the following units of storage in descending<br> order. B, TB,KB, GB,MB
    5·1 answer
  • What is subscriber billing in Google Play and where does the money go?
    5·1 answer
  • Which of the following is a correctly named cell?<br> B8<br> BB-8<br> 8-B<br> 8B
    11·1 answer
  • What adaptation Judy and her parents have that help them run from predators coming?​
    6·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    5·1 answer
  • Heyyyyyy<br> byeeeeeeeeeeeeeeeeeeeeeee
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!