Question

Given a non-negative integer, return true if most of its digits are odd (more digits are odd than are even). An odd number is\

Please use JAVA to solve this problem. Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1
boolean mostlyOdd(int num) {
    int d, evens = 0, odds = 0;
    while (num > 0) {
        d = num % 10;
        if (d % 2 == 0) evens++;
        else odds++;
        num /= 10;
    }
    return odds > evens;
}
Add a comment
Know the answer?
Add Answer to:
\ Please use JAVA to solve this problem. Thanks! Given a non-negative integer, return true if...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm having trouble making a code for this problem, my class is working with java in...

    I'm having trouble making a code for this problem, my class is working with java in while loops and for loops. Write a method that returns true if an integer parameter n is a perfect number, false otherwise. (recall a perfect number is a number whose sum of its proper factors is equal to itself) (Precondition: n >= 1 .. means you are to presume n is positive) : EXAMPLE: 6 is a perfect number 1 2 3 equals 6...

  • Please write a Java program: Given an array of positive integers, return a count of the...

    Please write a Java program: Given an array of positive integers, return a count of the number of even integers. countEvens([2, 3, 5])-1 countEvens([4, 20]) - 2 countEvens([3, 7, 1, 11]) 0 Go Save, Compile, Run (ctrl-enter) int countEvens (int[] nums) {

  • Please do both parts (in Java); thanks! An Armstrong number of three digits is an integer...

    Please do both parts (in Java); thanks! An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3^3 + 7^3 + 1^3 = 371. Draw the flowchart and write a Java code to find ALL Armstrong number in the range of 0 and 999. You should write your code in two ways: (Yes as if you are...

  • I need help with these java codingbat questions please: Create a method that creates a user...

    I need help with these java codingbat questions please: Create a method that creates a user id, where the user id is made up of the first letter of the first name and the entire last name. e.g. john smith ->jsmith getUserld("bill", "gates")-"bgates" getUserId("steve", "jobs")"sjobs" getUserId("larry", "page") -"lpage" Go Save, Compile, Run (ctrl-enter) public String getUserId( String firstName, String lastName) Given a number n, create an array with elements starting from 1 to n. e.g. 5 > getNumArray(1) [1] getNumArray...

  • java programming. One. Write a method public boolean hasOnlyoddDigits(int n) that returns true if its parameter...

    java programming. One. Write a method public boolean hasOnlyoddDigits(int n) that returns true if its parameter n contains only odd digits (1, 3, 5, 7, or 9), and returns false otherwise. Zero is counted as an even digit whenever it appears inside the number. Remember that for a positive integer n, the expression (n % 10) gives its last digit, and the expression (n / 10) gives its other digits. Correct answer true false false false 357199 7540573 97531000

  • This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string...

    This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string and a non-negative int n, return a larger string that is n copies of the original string. string_times('Hi', 2) – 'HiHi' string_times('Hi', 3) - 'HiHiHi' string_times('Hi', 1) – 'Hi' Solution: Go Save, Compile, Run (ctrl-enter) Show Solution def string_times (str, n): def string_times(str, n): result = "" for i in range(n): # range(n) is [0, 1, 2, .... n-1] result = result + str...

  • 1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately...

    1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately terminating the list reading when the sentinel value (lets use -9999) is entered. The program should then correctly report the number of non-negative scores entered and the arithmetic mean (average) of those scores 2. Demonstrate your programs behavior in response to errors on input (that is, show that it faithfully rejects improper input such as alphabetic characters, decimal points, and commas). Here are some...

  • write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative...

    write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative integer  n and a character  c and return a String consisting of n identical characters that are all equal to c. Write a method  named  printTriangle that receives two integer  parameters  n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...

  • // I need help with the following questions. Please use java programming ECLIPSE language to solve...

    // I need help with the following questions. Please use java programming ECLIPSE language to solve the questions. YOU ONLY NEED TO DIRECTLY COPY IT IN YOUR ECLIPSE APPLICATION AND RUN IT. I NEED THOSE PART WHICH IS SAYS --> "TO BE COMPLETED" I NEED HELP WITH [GET*] AND [REPLACE ALL] AND [ADD INT DOUBLE] PLEASE. import java.util.ArrayList; public class CustomArrayList { //instance variables public int[] data; //data.length gives the capacity public int nItems; //nItems gives items currently in the...

  • Recursion Exercises These exercises provide practice with recursion in Java. Please add notes if possible. Objectives...

    Recursion Exercises These exercises provide practice with recursion in Java. Please add notes if possible. Objectives Module: To write recursive solutions for basic problems that require iteration. To identify and address base cases in a recursive method. Reminders during development Each of your solutions to the problems below should be in their own method. If a method header is provided for a problem, then your solution should have that exact method header. Any changes to the method header will receive...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT