Question

: Given a specific number, consider all the numbers from 1 to given number and calculate...

: Given a specific number, consider all the numbers from 1 to given number and calculate how many of them are odd, even and multiples of 3. For instance:
number = 9
then consider {1, 2, 3, 4, 5, 6, 7, 8, 9}
count of even numbers = 4   // 2, 4, 6, 8
count of odd numbers = 5   // 1, 3, 5, 7, 9
count of multiples 3 = 3       // 3, 6, 9
note. You do not have to list all the numbers, you just need to count how many.
For the problem above, create the pseudocode, trace table, java code, screenshot of output

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class NumberCount {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter number: ");
       int n=sc.nextInt();
       int evenCount=0,oddCount=0,mulitplesThree=0;
       for(int i=1;i<=n;i++) {
           if(i%2==0)
               evenCount++;
           else
               oddCount++;
           if(i%3==0)
               mulitplesThree++;
       }
       System.out.println("Count of even numbers = "+evenCount);
       System.out.println("Count of odd numbers = "+oddCount);
       System.out.println("Count ofmulitples 3 = "+mulitplesThree);
      
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
: Given a specific number, consider all the numbers from 1 to given number and calculate...
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
  • please answer all qustions use this input(6587) Problem Description: Consider afour digit number corresponding to number...

    please answer all qustions use this input(6587) Problem Description: Consider afour digit number corresponding to number of letters in your full name. Input this number in your program to compute the below: a) Count the number of digits in the input number: Suppose if the input number is 3561, output should be 4. b) Compute the sum of digits in the input number: Suppose if the input number is 3561, output should be 3+5+6+1 = 15. C) Reverse the digits...

  • A large collection of one-digit random numbers should have about 50% odd and 50% even digits...

    A large collection of one-digit random numbers should have about 50% odd and 50% even digits because five of the ten digits are odd (1, 3, 5, 7, and 9) and five are even (0, 2, 4, 6, and 8) a. Find the proportion of odd-numbered digits in the following lines from a random number table. Count carefully. 9 0 49 0 5 0 7 8 1 7 8 3 4 5 0 7 1 5 7 5 1 2...

  • Write a program in javascript, that take numbers from 1….20 in an array. Separate Even and...

    Write a program in javascript, that take numbers from 1….20 in an array. Separate Even and Odd numbers by using conditional statement. Figure # 01 is the output of this file on web browser. Example: Odd Number = 1 Even Number = 2 Odd Number = 3 Even Number = 4 Odd Number = 5 Even Number = 6 Odd Number = 7 Even Number = 8 Odd Number = 9 Even Number = 10 Odd Number = 11 Even...

  • How many different 4-digit numbers can be made from the set of 8 numbers {1, 2,...

    How many different 4-digit numbers can be made from the set of 8 numbers {1, 2, 3, 4, 5, 6, 7, 8} if: The resulting number must be an odd number and repeats are NOT allowed.

  • java 1. Write an application that generates n random integers in the range provided the user....

    java 1. Write an application that generates n random integers in the range provided the user. Use method genrate Even to generate even numbers only and generateOdd to generate odd numbers void generateOdd(int n, int r1, int r2); void generateEven(int n, int r1, int r2); Sample run: How many integers you have?5 What are your number ranges? 3 10 The generated even numbers are 6 4 8 10 6 The generated odd numbers are 37 9 35

  • Create in Java: 1. Create a (nested) for loop that given a number prints a line...

    Create in Java: 1. Create a (nested) for loop that given a number prints a line with the number repeated as many times as the number itself, for example: 22 333 4444 000.- 2.Modify the nested for loop to specify in each line if the numbers are even or odd. For example: 1 (odd) 22 (even) 333 (odd) 4444 (even) Dona.... 3. Modify the nested for loop to only print odd numbers. For example: 333 55555 annan..

  • write a code that will print all numbers and their squares between 1 and a given...

    write a code that will print all numbers and their squares between 1 and a given positive integer examples: if a given integer is 7 then ouput is: 1 1 2 4 3 9 4 16 5 25 6 36 7 49 the full java code using repetition and BASIC JAVA language for beginners

  • (Done in Eclipse Java) 1. Given an integer between 1—100 captured from a user, perform the...

    (Done in Eclipse Java) 1. Given an integer between 1—100 captured from a user, perform the following conditional actions: • If is odd, print Weird • If is even and in the inclusive range of 2 to 5, print Not Weird • If is even and in the inclusive range of 6 to 20, print Weird • If is even and greater than 20, print Not Weird Note: Validate that your algorithm works for all cases. 2. Read an integer...

  • Given the following sets: S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},...

    Given the following sets: S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, Even numbers A = {2, 4, 6, 8, 10}; Odd number B = {3, 5, 7, 9}; Natural numbers N = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and Prime numbers C = {2, 3, 5, 7} Find the following: a) A ∪ C b) A ∩ N c) A ’ d) B ∩ N e) B ∪ N f) C...

  • Java Programmming Given three numbers from user input, decrement the first number by 2 and increment...

    Java Programmming Given three numbers from user input, decrement the first number by 2 and increment the second number by 1, Then do the magic calculations as follows: get the sum of the first two numbers, deduct the third number from the second and get the product of the first and third number, then sum up the results of the three magic calculations. Sample run 1:                                     Enter three numbers separated by spaces: 4 2 3      Output: Result of Magic calculations...

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