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
What is a scratch application pls help me build a game through scratch step by step​
borishaifa [10]

Answer:

Scratch is the a coding community and a coding language with simple visual interface that allows people to create digital stories, games and animeations ect.

Explanation: Migth be able to help depending on waht you are making

6 0
2 years ago
Write a function negateOdds that takes a list of integers and returns a list of integers with all of the odd integers negated. n
aleksley [76]

Is this computer science?

If so, then the function you would need for your code is this...

_____

if (someValue%2 != 0) {

 value *= -1;

        }

_____

//basically <u>number%2 == 0</u> means even so "!" means false so "not even" meaning "odd."

Assuming you are doing an array list (given a set value) or a for-loop with an

int someValue = Integer.parseInt(args[i]); inside (not given a set value and not restricted)

Otherwise ignore me....lol

5 0
3 years ago
Send the memes whoever is the best will get that crown thing lol
shutvik [7]
I have to type 20 characters here so...

4 0
3 years ago
Read 2 more answers
A search engine company needs to do a significant amount of computation every time it recompiles its index. For this task, the c
romanna [79]

Answer:

See attached pictures for detailed answer.

Explanation:

See attached pictures for explanation.

5 0
2 years ago
How can I, fill the application form for jobs. [such as Macdonal's jobs].?
pochemuha
I don’t really understand what this question is asking 100%, but you can either walk into the McDonald’s you want to work at and ask for an application. They might give it to you, but will most likely tell you to apply online.

If they do tell you to apply online, go to the McDonald’s website and scroll all the way down to the bottom.

There are sections you can choose such as: About Us, Careers, Services, Community, and Contact Us.

Clearly you want to go to Careers.

Under Careers are: Education Opportunities, Employee Perks, Meet Our People, Working With Us, and Apply Now.

Click Apply Now and start your application.

5 0
3 years ago
Other questions:
  • If you want to be more efficient at using the World Wide Web, refresh the page often.
    7·1 answer
  • Which type of computer network ensures high quality​
    9·1 answer
  • What effect does the interconnectedness of modern media have on society?
    14·2 answers
  • Presentation software is the best file type for writing a research paper. <br> True <br> False
    10·1 answer
  • Sam plans to use this image in artwork for a brochure about airplanes. Which principles of page layout is Sam planning to use in
    11·1 answer
  • Photoshop files are generally small in size. True or false
    13·1 answer
  • Wilma is looking for facts about social media for her research project. What fact should she use for her project?
    15·1 answer
  • A __________is a software program that appears to be a physical computer and executes programs as if it were a physical computer
    14·1 answer
  • 12. Why is it so important to pay attention to your digital reputation?
    14·1 answer
  • Connect research concepts to their definitions
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!