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
I have no idea which one please help!
shutvik [7]

Answer:

i think its the second one

Explanation:

brainliest pls

6 0
2 years ago
Read 2 more answers
All spreadsheet formula should start with
inysia [295]
A formula in Excel will ALWAYS start with = then the function name like
=SUM(A1:A5)
5 0
3 years ago
Projects used for print and web have different ?
mr Goodwill [35]

Answer:

Sizes

Explanation:

6 0
3 years ago
What educational site could I make a screen capture tutorial on? I need ideas for a school project.
snow_tiger [21]

You Need Software To Screen Capture

The Software You can use is OBS its free and there are watermarks

4 0
2 years ago
So I emailed Brainly to deleted my account. Why haven’t they done so yet? I don’t want to get charged money for this app I was p
joja [24]

Answer:

Go to the Use the profile settings page. Click on "I want to delete my account" button located inside the Privacy tab on your profile settings page. Enter your Password.

Explanation:

8 0
3 years ago
Other questions:
  • When pasting an existing chart into a Word document, you can choose to _______ using the Paste Options button.
    7·2 answers
  • What are a few benefits of virtualization?<br> How do they benefit ?
    9·1 answer
  • Write a program to add two number marie simulator.
    15·1 answer
  • Professional photography is a competitive job field. <br> true <br> false
    12·2 answers
  • .<br> 1. Press the _______ key to move to the next cell in a row.
    14·2 answers
  • How do you freeze the total cell so that it doesn't change when copied?
    6·1 answer
  • About how long did it take to photograph Daguerre's photograph of the street?
    7·1 answer
  • In batch operating system three job J1 J2 and J3 are submitted for execution each job involes an I/O activity a CPU time and ano
    13·1 answer
  • computer is an electronic machine that is used for data processing to produce meaningful information explain in statement​
    5·1 answer
  • In 1980, IBM's cheapest computer was more affordable than Apple's.<br><br><br> True<br><br> False
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!