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
Andrej [43]
2 years ago
15

Create a Boolean function odd_number_digits(n) that returns True when a positive integer has an odd number of digits. (You may a

ssume that I will not use a number greater than 1,000,000.) Then, use it to make a
function sum_odd_digits(n) that sums all the numbers from 0 to n that have an odd number of digits.

Computers and Technology
1 answer:
Snowcat [4.5K]2 years ago
8 0

Answer:

Following are the code to this question:

import java.util.*;//import package for user input

public class Main//defining class main

{

   public static boolean odd_number_digits(int n)//defining boolean method odd_number_digits

   {

       if(n>0 && n%2!=0)//defining if block that check value is positive and odd number

       {

       return true;//return value true

       }

       else//defining else block

       {

           return false;//return false value

       }

   }

   public static void  sum_odd_digits(int n)//defining a method sum_odd_digits

   {

       int sum=0,i;//defining integer variable

       for(i=0;i<=n;i++)//defining for loop

       {

           if(i%2!=0)//defining if block for odd number

           {

               sum=sum+i;//add odd number

           }

       }

      System.out.print(sum);//use print method to print sum value

   }

public static void main(String[] args) //defining main method

   {

       Scanner ox=new Scanner(System.in);//creating Scanner object

       int n= ox.nextInt();//defining integer variable for input value

       System.out.print(odd_number_digits(n)+ "\n");//use print method to call method

       System.out.println("Sum of odd numbers: ");//print message

       sum_odd_digits(n);//calling method

   }

}

Output:

please find the attachment.

Explanation:

In the above code, two methods "odd_number_digits and sum_odd_digits" are defined in which the first method return type is boolean because it will true or false value, and the second method returns the sum of odd numbers.

In the "odd_number_digits" method,  an integer variable passes as an argument and inside the method, if block is used that check value is a positive and odd number then it will return a true value.

In the "sum_odd_digits" method, it accepts an integer parameter "n", and define integer variable "sum" inside the method, which uses the for loop, inside the loop if block is used that counts odd numbers and adds its in sum and print its value.

You might be interested in
Why should spain go to Africa ​
uysha [10]

Answer:

to learn about their cultural heritage and historical significance

3 0
3 years ago
What advantage does a circuit-switched network have over a packet-switched network? What advantages does TDM have over FDM in a
White raven [17]

Answer and Explanation:

The benefit of circuit switching is that it has a specialized circuit without exchanging (guaranteed performance). Packet-Converting uses either TDM or FMD. TDM has the added benefit of being able to use most of the (multiplexing) bandwidth.

  • It is the most recognizable method used to create a communication over network is circuit switching.
  • It can be used for regular phone conversations.
  • This enables people to share devices and circuits for conversation.
  • Through network utilization, every user has an exclusive connection to a circuit.
8 0
3 years ago
Which of these is most closely associated with system control? (1 point) (Points : 1.5) boundary
Mademuasel [1]

Answer:C) Feedback

Explanation: System control is the controlling and managing activity of the system by commands ,regulations, management practices etc.It helps in the analyzation of the system and improving the ability of performing the tasks.Feedback is the component of the control system that is obtained as the output after the controlling  technique is applied in the system.

Other options are incorrect because environment is the surrounding of the system ,interface is the connection between the components of the system and boundary is not a technical term of control system.Thus, the correct option is option(C).

3 0
3 years ago
Ew<br>subject: Computer<br>11101÷101<br> binary operations<br>​
lions [1.4K]
11101 / 101 = 109.9
5 0
2 years ago
How to print something nad input on same line python
Serhud [2]
To get everything on one line with two inputs is not (easily) achievable, as far as I know. The closest you can get is: print 'I have', a=input() print 'apples and', p=input() print 'pears. '
7 0
2 years ago
Other questions:
  • What are the first two lines of defense a company should take when addressing security risks?
    10·1 answer
  • Not providing guarding or fall protection for workers on a 25-foot scaffold. The resulting fall would most likely end in death,
    6·1 answer
  • Compare GBN, SR, and TCP (no delayed ACK). Assume that the timeout values for all three protocols are sufficiently long such tha
    11·1 answer
  • What will be the output after the following code is executed? def pass_it(x, y): z = y**x return(z) num1 = 3 num2 = 4 answer = p
    7·1 answer
  • Hey system has defined specific Quetion that describe how signals are sent over connections. Which layer of the transmission con
    11·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·2 answers
  • Please help!!!! will mark brainliest!!
    7·2 answers
  • If you can name this you get 15 points: ↑↑↓↓←→←→βα
    10·1 answer
  • 2. Which of the following is a shortcut key to Exit from any operation?
    10·2 answers
  • Suppose the cache access time is 10ns, main memory access time is 200ns, and the cache hit rate is 90%. Assuming parallel (overl
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!