Question

This program should ask the user for the maximum number to print out to and then...

This program should ask the user for the maximum number to print out to and then print each evennumber starting from 0 to the maximum. You may want to use % operator which gives you the remainder. Some results of the operator is as follows:

• 0 % 2 = 0

• 1 % 2 = 1

• 2 % 2 = 0

• 3 % 2 = 1

• 4 % 2 = 0

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

import java.util.Scanner;

public class Tester2 {

      public static void main(String[] args) {

            // TODO Auto-generated method stub

            //Scanner function to get the input from keyboard

            Scanner scan = new Scanner(System.in);

            //Ask the user to enter Maximum number

            System.out.print("Maximum number to print: ");

            int max= scan.nextInt();

            //printing the maximum number

            System.out.println("Maximum number: "+max);

            System.out.println("Even number upto "+max);

            //Looping from 0 to maximum number to print the numbers upto maximum

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

                  if(i%2 ==0){

                        //If the remainder is 0 then the number is even

                        //If the number is even it is printed otherwise it is not printed

                        System.out.print(i+" ");

                        //If you want to print number per line you can use System.out.println in the above statement

                  }

            }

      }

}

Output:

Add a comment
Know the answer?
Add Answer to:
This program should ask the user for the maximum number to print out to and then...
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
  • Java program should ask the user for the maximum number to print out to and then...

    Java program should ask the user for the maximum number to print out to and then print each evennumber starting from 0 to the maximum. You may want to use % operator which gives you the remainder. Some results of the operator is as follows: • 0 % 2 = 0 • 1 % 2 = 1 • 2 % 2 = 0 • 3 % 2 = 1 • 4 % 2 = 0

  • IN PERL Write a program that will ask the user for a number and will print...

    IN PERL Write a program that will ask the user for a number and will print all the integers in order starting from 1 until the number. Use the <> operator to ask for the user's input. For this program you will write a countdown timer. Your time will count down from 1 minute (60 seconds) to 0. Once the timer gets to 0 seconds the system will display a message that reads: RING RING RING! -using do while-

  • Simple calculator program. The program should ask the user for a number, an operator, and then...

    Simple calculator program. The program should ask the user for a number, an operator, and then a second number. The operator should be either '+', '-', 'x', or '/'. The program should then report the answer to the problem. Use a switch statement, not an if statement. Note that "operator" is a reserved word in C++, so you cannot use it as a variable name. Use double variables and setprecision(2).

  • Write a program that will ask the user for a decimal number such as 18 and...

    Write a program that will ask the user for a decimal number such as 18 and prints the 16 bit binary equivalent of the number: 0000 0000 0001 0010 NOTE: Your output should be a binary string formatted by nibbles (spaces every four bits): 0000 0000 0010 1110 1010 0111 1. Ask the user for a number and store it in an int variable called “number”. 2. Find out how many bits you want to use to represent this number....

  • Please solve it by Python 3 Write a program that asks the user for a positive...

    Please solve it by Python 3 Write a program that asks the user for a positive integer limit and prints a table to visualize all factors of each integer ranging from 1 to limit. A factor i of a number n is an integer which divides n evenly (i.e. without remainder). For example, 4 and 5 are factors of 20, but 6 is not. Each row represents an integer between 1 and 20. The first row represents the number 1,...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • the user should be prompted to enter an integer and then your program will produce another...

    the user should be prompted to enter an integer and then your program will produce another integer depending on whether the input was even or odd. The following is an example of what you might see when you run the program; the input you type is shown in green (press Enter at the end of a line), and the output generated by the program is shown in black text. Enter an integer: 1234 Number is even, taking every other digit...

  • Write a program and flowchart. The program should ask the user how many customers they want...

    Write a program and flowchart. The program should ask the user how many customers they want to track. Then, it asks for customer numbers, and sales by customer. At the end, it prints out the customer number, the customer sales, and then the total sales and average sales. You must use two different arrays, one for customer number, and one for sales. These are, in effect, parallel arrays.   You must use a "while" loop to gather customer number and sales....

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the smallest integer among them and print it on the screen. Typical output screen should be as following: Write a complete C++ program to ask the user to enter 4 integers. The program must use a functionto find the smallest integer among them and print it on the screen. Typical output screen should be as following: Note: the code...

  • write in python Create a program that will ask the user for a list of integers,...

    write in python Create a program that will ask the user for a list of integers, all on one line separated by a slash. construct a list named "adj_numbers" which contains the users input numbers after subtracting 2 from each number. then print the resulting list. the input statement and print statement are given to you in the starting code. a sample run of the program is as follows: Enter a list of integers, separated by slashes: 7/3/6/8 resulting list:...

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