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
Put the steps you would use to insert and label an endnote in order.
Sholpan [36]

Answer:

2nd- step 1, 3rd- step 2, 1st- step 3, 4th- step 4

Explanation:

1. locate the reference tab

2. click the insert endnote option

3. type your endnote label

4. type the text you want the endnote to follow

3 0
3 years ago
The two internal networks are using the same internal network. Does this work? Why or Why not?
lana [24]

Answer:yes

Explanation:

They are the same network

3 0
3 years ago
After several incidents in __________ the company’s computer systems were not ready to support new products, the CEO established
frutty [35]

Answer:

Cross-functional team

Explanation:

The CEO would establish a CROSS-FUNCTIONAL TEAM wWichita would consist of employees from different departments, who would work together on future product rollouts.

Cheers

4 0
4 years ago
using the class c ip address 195.1.1.0 (class c means that only the last octet can be used for subnet and host addresses, or sta
Lelechka [254]

Answer:

Explanation:

Given a class C IP address

195.1.1.0

Existing mask is 255.255.255.0

We want to have 12 hosts on 10 subnets.

A class C address has 8 bits of the host which will give, n=8

2ⁿ - 2 = 254 hosts

Current mask= 255.255.255.0

Bits needs for 10 subnets

2ⁿ = 10, n = 4bits

n = 4 = 2⁴ = 16 possible subnets

Now, bit needed for 12host, n =4bits

2⁴-2 = 14 possible host,

Total of 8 bits needed so therefore we can use as 4bits for the subnet.

So we could have

4 bit subnet and 4 bits hosts

11110000 = 240decimals

Final possible masks is

255.255.255.240

5 0
3 years ago
What is access 2016?
Goryan [66]

Access 2016 is what it is

4 0
4 years ago
Other questions:
  • Suppose you have a certain amount of money in a savings account that earns compound monthly interest, and you want to calculate
    10·2 answers
  • Question 5
    5·1 answer
  • In a switch statement, if a break statement is missing, _______________. Select one: a. the default case is automatically execut
    15·1 answer
  • Need Help !!! Please
    8·1 answer
  • I play Among us :) hbu
    7·2 answers
  • When max() function is used on lists of words, what does max() find? For example:
    13·1 answer
  • What is the significance of the following terms A A L U control unit in the CPU​
    13·1 answer
  • Select the things you can do when working with rows in columns in a spreadsheet:
    12·1 answer
  • ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    14·1 answer
  • Which principle or element of layout design is highlighted in this event poster?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!