1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NemiM [27]
3 years ago
6

Write a program that reads an integer and determines and prints whether it's odd or even. [Hint: Use the remainder operator (%).

An even number is a multiple of two. Any multiple of 2 leaves a remainder of zero when divided by 2.]
Computers and Technology
1 answer:
Sloan [31]3 years ago
4 0
<h2>Explanation:</h2>

The source code, written in Java, and a sample output have been attached to this response. It contains comments explaining certain parts of the code.

A few things to note are;

(i) The Scanner class is imported to allow user's interact with the program. This is done by writing the import statement at the top of the code as follows;

<em>import java.util.Scanner;</em>

<em />

(ii) An object of the Scanner class is created to receive inputs from the user. The object is called input and created as follows;

<em>Scanner input = new Scanner(System.in);</em>

(iii) Since the user is expected to enter an integer, the nextInt() method of the Scanner object is used to receive the integer and this is saved in a variable called <em>number. </em>i.e

<em>int number = input.nextInt();</em>

<em></em>

(iv) A number x, is even if its remainder when divided by 2 is 0. i.e

if x % 2 = 0, then x is even. Otherwise it is odd.

The user's input received and saved in a variable called <em>number </em>is then checked using if and else blocks to check if it is even or not and can be written as follows;

<em>if(number % 2 == 0){</em>

<em>    System.out.println(number + " is even");</em>

<em>}else {</em>

<em>    System.out.println(number + " is odd");</em>

<em>}</em>

You might be interested in
Who designed the apple i computer in 1976?
guajiro [1.7K]

Steve jobs designed the first apple computer


6 0
3 years ago
Read 2 more answers
What does a spam e-mail normally promise you?
nlexa [21]
The answer is a virus
7 0
3 years ago
Which is a feature of a search engine? stores web pages belonging to a single website displays web pages within a browser finds
faltersainse [42]
Finds web pages that matches key words
8 0
3 years ago
Peter is explaining the steps to create a fire effect in an image to his class. Help Peter pick the correct word to complete the
Pavel [41]

Answer:

The answer would be "Blending"

Explanation:

I took the test and checked over my answers

4 0
3 years ago
doubleUp Write a method doubleUp that doubles the size of a list of integers by doubling-up each element in the list. Assume the
Maslowich

Answer:

The solution in Python is as follows:

class myClass:

     def doubleUp(self,myList):

           myList[:0] = myList[::2] = myList[1::2] = myList[:]

       

mylist =  [1, 3, 2, 7]

list = myClass()

list.doubleUp(mylist)

print(mylist)

Explanation:

To create a method in Python, the first step is to create a Class.

This is done in the following line:

class myClass:

Then this line defines the method

     def doubleUp(self,myList):

This line duplicates the elements of the list

           myList[:0] = myList[::2] = myList[1::2] = myList[:]

This defines the list        

mylist =  [1, 3, 2, 7]

This creates an instance of the class

list = myClass()

This passes the list to the doubleUp method

list.doubleUp(mylist)

This prints the duplicated list

print(mylist)

4 0
3 years ago
Other questions:
  • Reflexes are basically "hard-wired" into the CNS. Anatomically, the basis of a reflex is an afferent neuron that synapses direct
    10·1 answer
  • I need help with Microsoft.
    6·1 answer
  • Clicking a _____ name opens a drop-down list of commands and options.
    6·1 answer
  • Use the Bisection Method to find the root 2. Write a main program and a function program 3. Main Program a. define constants b.
    9·1 answer
  • Which keys should you press to insert a comment in OpenOffice Writer?
    15·2 answers
  • What do you mean by real time system? Why real time system needs to response within limited time?
    6·1 answer
  • What is a file explore?
    12·1 answer
  • Explain the importance of technology in at least 100 words
    11·1 answer
  • What is the datapath of add instruction?
    6·1 answer
  • Which X software package is designed to be a more streamlined and easier to use replacement for the X Window System
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!