Question

Write a JAVA code snippet which prints out numbers between 0 and 1,000,000, BUT only print...

Write a JAVA code snippet which prints out numbers between 0 and 1,000,000, BUT only print the numbers which are a multiple of 3.

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

class Main {

    public static void main(String[] args) {

        // prints numbers from 0 to 1,000,000

       for(int i = 0; i < 1000000; i++) {

           // prints only those which are multiple of 3

            if(i % 3 == 0) {

               System.out.println(i);

           }

        }

   }

}

ABOVE CODE WILL OUTPUT THE NUMBERS IN THE GIVEN RANGE WHICH ARE ONLY MULTIPLE OF 3.

FOR HELP PLEASE COMMENT.
THANK YOU.

Add a comment
Know the answer?
Add Answer to:
Write a JAVA code snippet which prints out numbers between 0 and 1,000,000, BUT only print...
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
  • Write a Java program with a while statement that will only print out the numbers 50,...

    Write a Java program with a while statement that will only print out the numbers 50, 45, 40, 35, 30, 25.

  • 1. Write a code snippet Write a code snippet that asks the user to enter a...

    1. Write a code snippet Write a code snippet that asks the user to enter a name and a major one at a time and creates a dictionary with keys corresponding to names and values corresponding to majors. Assume that the user enters “alice”, “bio”, “mark”, “engineering”. >>>d = {} >>> your code starts here 2.Based on your code above: >>> print(d) 3.Write a code snippet Write a code snippet that creates a dictionary (records) using keys from a frozenset...

  • Java question Q1) Use the following code snippet which generates a random sized array with random...

    Java question Q1) Use the following code snippet which generates a random sized array with random contents to complete the following problems: public int [] createRandomArray() {         int size = (int) (Math.random() * 10) + 1;         int[] array = new int [size];         for (int i = 0; i < array.length; i++) {             array[i] = (int) (Math.random() * 10 ) + 1;         }         return array;     } Assignment...

  • Java Programming. Write your own source code with comments. (Print distinct numbers) Write a program that...

    Java Programming. Write your own source code with comments. (Print distinct numbers) Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct...

  • Write a python code that takes in an number 0-9 and prints out the word of...

    Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...

  • What number will the following code snippet print? int numbers[8] = { 34, 42, 6, 11,...

    What number will the following code snippet print? int numbers[8] = { 34, 42, 6, 11, 29, 1, 89, 62}; cout << numbers[7];

  • For JAVA Please post code in bold. Thank you. Print numbers 0, 1, 2, ..., userNum...

    For JAVA Please post code in bold. Thank you. Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Challenge 4.6.1: Nested loops ndent...

  • Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive...

    Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive integers). • Prompts the user for a starting number: say 'x' • Prompts the user for an ending number: say 'y' • Prints out the multiplication table of 'x' up to the number 'y' SPECIFIC REQUIREMENTS 1. You must use the following method to load the array: public static void loadArray(int table[][], int x, int y) 2. You must use the following method to...

  • JAVA. Write a program that reads in a series of positive integers and prints out the...

    JAVA. Write a program that reads in a series of positive integers and prints out the maximum value entered. The user will indicate they are finished entering numbers by entering zero or a negative integer.

  • 8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by...

    8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by either 3 or 7. ​ (b) Write a program that prints all of the numbers from 0 to 102 divisible by both 3 and 7 (c) Write a program that prints all of the even numbers from 0 to 102 divisible by both 3 and 7 (d) Write a program that prints all of the odd numbers from 0 to 102 divisible by both...

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