Hasanodddigit that returns whether any digit

Assignment Help JAVA Programming
Reference no: EM13161162

d named hasAnOddDigit that returns whether any digit of a positive integer is odd. Your method should return true if the number has at least one odd digit and false if none of its digits are odd. 0, 2, 4, 6, and 8 are even digits, and 1, 3, 5, 7, 9 are odd digits.

For example, here are some calls to your method and their expected results:

CallValue Returned
hasAnOddDigit(4822116) true
hasAnOddDigit(2448) false
hasAnOddDigit(-7004) true

You should not use a String to solve this problem.

my code:

public boolean hasAnOddDigit(int num){
// You do not need to make a copy of num, because
// of pass-by-value semantic: since num is a copy,
// you can change it inside the method as you see fit.
while (num > 0) {
int digit = num % 10;
if (digit % 2 == 1) return true;
num /= 10;
}
// If we made it through the loop without hitting an odd digit,
// all digits must be even
return false;
}

error:

#nameexpected returnyour returnresult
1 hasAnOddDigit(4822116) true true icon pass
2 hasAnOddDigit(2448) false false icon pass
3 hasAnOddDigit(8910437) true true icon pass
4 hasAnOddDigit(6022048) false false icon pass
5 hasAnOddDigit(824876248) true true icon pass
6 hasAnOddDigit(1375335) true true icon pass
7 hasAnOddDigit(42) false false icon pass
8 hasAnOddDigit(70) true true icon pass
9 hasAnOddDigit(4) false false icon pass
10 hasAnOddDigit(3) true true icon pass
11 hasAnOddDigit(0) false false icon pass
12 hasAnOddDigit(-7004) true false icon fail
13 hasAnOddDigit(-24806) false false icon pass

Reference no: EM13161162

Questions Cloud

What is the energy required to move a mole of urea out : What is the energy required to move a mole of urea out of the kidney cells and into the urine?
What is the minimal total weight of cylinders : A scuba diver uses a special equipment for diving. He has a cylinder with two containers: one with oxygen and the other with nitrogen. Depending on the time he wants to stay under water and the depth of diving the scuba diver needs various amount of ..
Create a file, shared.txt : When your program starts, it shall do the following:1. Create a file, SHARED.txt, in the current directory (cwd). 2. Write it's pid (Process ID) followed by a Carriage Return and Newline in the file.
State divers breathing compressed air : The solubility of N2 in blood can be a serious problem (the "bends") for divers breathing compressed air (78% N2 by volume) at depths greater than 50 ft.
Hasanodddigit that returns whether any digit : d named hasAnOddDigit that returns whether any digit of a positive integer is odd. Your method should return true if the number has at least one odd digit and false if none of its digits are odd. 0, 2, 4, 6, and 8 are even digits, and 1, 3, 5, 7, 9 a..
Determine the microcanonical partition function : Determine the microcanonical partition function, omega. Determine fundamental relation of system, using Stirling's approximation Determine the energy and heat capacity for the system as a function of temperature using Stirling's approximation. Det..
Explain what is the partial pressure of nocl : what is the partial pressure of NOCl which reacted in order for the partial pressure of NO to be .084 atm? what is the partial pressure of Cl_2 at equilibrium what is the magnitude of K_p for the equation above?
Write c++ program that reads in the average monthly rainfall : Write a C++ program that reads in the average monthly rainfall for a city for each month of the year and then reads in the actual monthly rainfall for each of the previous 12 months
State and draw the six conformers in newman projection : Draw the six conformers in newman projection for the 60 degree intervals from 0 to 360 degrees for carbon atoms 3 and 4. Clearly show which carbon is represented by the "dot" and the "circle" Show which C

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create online store web site

the Java and JSP source codes and SQL scripts for creating a database in Oracle - any configuration files used

  Communication with an smtp server

Develop a graphical user interface based java program that can communicate with a real SMTP email server for sending emails

  Create a driver class in java

Your project is to create a driver class that uses SuperJavaIceCreamClass.

  Write a program to find solution tocryparithmetic puzzle

Write a program (Crypta.java) that finds a solution to the cryparithmetic puzzle: TOO + TOO + TOO+ TOO = GOOD

  Develop java code to compute monthly rent for housing units

Develop a java code that computes monthly rent for 3 housing units namely Bungalows,Apartments and hostels. All housing units have got size,color and monthly rental rate.

  Write down java program for furniture company

Write down a Java program for the furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany. Illustrate price of table manufactured with chosen wood.

  Utilizes a good design process

Analyze, design, and document a simple program that utilizes a good design process and incorporates sequential, selection and repetitive programming statements as well as at least one function call and the use of at least one array.

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

  Develop a gui based java program

Designing and developing a College Registration program

  Multiple choice java programming questions

Determine which of the following may be a violation of information hiding if inserted for the comment above?

  Write a program to register students for a college

Students have names, addresses and courses. Implement the interface class RegisterStudent. RegisterStudent has one method, public boolean register, which returns the boolean value of true or false if the student is successfully registered for the ..

  Write java program which will permit user to make selection

Write the Java Program which will permit the user to make selection. You will present user with two options to perform, then you will perform action selected by user.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd