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]
3 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]3 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
Write a program that, given an integer, sums all the numbers from 1 through that integer (both inclusive). Do not include in you
fgiga [73]

Answer:

let n = 10;

let sum = 0;

for(i=1; i<=n; i++) {

if ((i%5) && (i%7)) {

 sum += i;

}

}

console.log(`Sum 1..${n} excluding 5 and 7 multiples is ${sum}`);

Explanation:

This is in javascript.

example output:

Sum 1..10 excluding 5 and 7 multiples is 33

5 0
3 years ago
In two to four sentences, describe how you would select a function.
Mila [183]

Explanation:

As a result, it is important not to overlook any of the sources of information that indicate what the form of the model should be. Answer Not ...

Knowing Function Types Helps: Another helpful ingredient in model selection

5 0
3 years ago
When a user problem cannot be solved by the help desk at the first level of resolution, the problem is ___________ to the second
PIT_PIT [208]

Answer: escalated

Explanation:

7 0
3 years ago
What can be done to solve unemployment problem?​
Anna [14]

Answer:

saving small business

tax credits

construction jobs

more assistance to self employed peopl

4 0
3 years ago
BJP4 Self-Check 7.21: swapPairs<br><br> plsssss
Vedmedyk [2.9K]

Answer:

needs more expiation

Explanation:

add a worksheet to the question

6 0
3 years ago
Other questions:
  • A technician is working at a client's office after hours and needs two cables to finish the work but does not have immediate acc
    7·1 answer
  • If you are asked to list your favorite websites in no particular order, you are relying on
    8·1 answer
  • Selena needs to insert a comment in a webpage's code to ensure that other web team members who work with the page code understan
    15·1 answer
  • What would be a standard way for anyone outside an agile team( for example, delivery partner partner of the account, head of the
    14·1 answer
  • Examine the following piece of code and determine the data type of the function's return value.
    11·1 answer
  • 2. Which of the following statements describes a need or problem that can be solved using the technology design process.
    14·1 answer
  • Please can someone help my assignment.​
    13·1 answer
  • 1. It is one way to attain one's holistic health condition.​
    9·1 answer
  • Create an application named SalesTransactionDemo that declares several SalesTransaction objects and displays their values and th
    12·1 answer
  • When a person's personal information is collected by other parties, it refers to the issue of
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!