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
Fantom [35]
3 years ago
10

in java how do i Write a method named isEven that accepts an int argument. The method should return true if the argument is even

, or false otherwise. Also write a program to test your method.
Computers and Technology
1 answer:
Veseljchak [2.6K]3 years ago
3 0
<h2>Answer:</h2><h2>============================================</h2>

//Class header definition

public class TestEven {

   

   //Method main to test the method isEven

   public static void main(String args[ ] ) {

       

       //Test the method isEven using numbers 5 and 6 as arguments

       System.out.println(isEven(5));

       System.out.println(isEven(6));

     

   }

   

   //Method isEven

   //Method has a return type of boolean since it returns true or false.

   //Method has an int parameter

   public static boolean isEven(int number){

       //A number is even if its modulus with 2 gives zero

      if (number % 2 == 0){

           return true;

       }

       

       //Otherwise, the number is odd

       return false;

   }

}

====================================================

<h2>Sample Output:</h2>

=========================================================

false

true

==========================================================

<h2>Explanation:</h2>

The above code has been written in Java. It contains comments explaining every part of the code. Please go through the comments in the code.

A sample output has also been provided. You can save the code as TestEven.java and run it on your machine.

You might be interested in
Write a function `has_more_zs` to determine which of two strings contains # more instances of the letter "z". It should take as
nekit [7.7K]

Answer:

// Method's name: has_more_zs

// Parameters are text1 and text2 to hold the two phrases to be tested

public static String has_more_zs(String text1, String text2) {

 // Create and initialize z1 to zero

 // Use z1 to count the number of zs in text1

 int z1 = 0;

 // Create and initialize z2 to zero

 // Use z2 to count the number of zs in text2

 int z2 = 0;

 

 //Create a loop to cycle through the characters in text1

 //Increment z1 by one if the current character is a 'z'

 int i = 0;

 while (i < text1.length()) {

  if (text1.charAt(i) == 'z' || text1.charAt(i) == 'Z') {

   z1 += 1;

  }

  i++;

 }

 //Create a loop to cycle through the characters in text2

 //Increment z2 by one if the current character is a 'z'

 

 i = 0; //Re-initialize i to zero

 

 while (i < text2.length()) {

  if (text2.charAt(i) == 'z' || text2.charAt(i) == 'Z') {

   z2 += 1;

  }

  i++;

 }

 

 

 //Using the values of z1 and z2, return the necessary statements

 if (z1 > z2) {

  return "The phrase '" + text1 + "'" + " has more occurences of z than the phrase " + "'" + text2 + "'";

 }

 else if (z1 < z1) {

  return "The phrase '" + text2 + "'" + " has more occurences of z than the phrase " + "'" + text1 + "'";

 }

 else if (z1 == z2) {

  return "The strings have the same number of z";

 }

 else {

  return "Neither string contains the the letter z";

 }

}

Explanation:

Explanation to answer has been given in the code as comments. Please refer to the comments for the details of the code.

The source code file has been attached to this response and saved as "NumberOfZs.java"

Hope this helps!

Download java
5 0
3 years ago
Why students might want headsets for their computers?
VARVARA [1.3K]
It can be noisy and distracting to students to listen to audio speakers when there are multiple computers in the classroom. Headphones help the students
3 0
3 years ago
Using the spreadsheet below, which formula can be used to determine Albert's hourly wage?
algol13

Answer:

It will be average (B2:C2)

as it will select all the data between B2 and C2

7 0
2 years ago
Read 2 more answers
Who conceptualizes the design and the working of a website
Citrus2011 [14]
Answer is "Web Designer".

Web Designers are the "artists" of the website. They conceptualize the layout and functionality of the site, from features to format. They may do little coding, and are mostly involved in the creative elements of web design. The Web Developer is less big-picture, and more knitty-gritty building of the website. She is the one who does the coding and actually builds the website, using the web designer's model. 
3 0
3 years ago
The term used to describe whereby old and new media are available via the integration of personal computers and high speed satel
garri49 [273]

The term used to describe whereby old and new media are available via the integration of personal computers and high speed satellite based phone or cable links is: media convergence.

<h3>What's a good illustration of media convergence? </h3>
  • Smartphones, laptops, and ipads are the finest instances of media convergence since they combine several forms of digital media, including radio, cameras, TVs, music, and more, into a single, straightforward gadget.
  • The blending of formerly separate media platforms and technologies through digitization and computer networking is referred to as media convergence. Another name for this is technical convergence.
  • Media ownership concentration, sometimes referred to as media consolidation or media convergence, is the process through which a smaller number of people or organisations come to control a larger portion of the mainstream media.
  • According to recent study, there is a rising amount of consolidation in the media sectors, which are already highly concentrated and controlled by a very limited number of companies.

To learn more about media convergence, refer to the following link:

brainly.com/question/25784756

#SPJ4

6 0
1 year ago
Other questions:
  • A type TW cable containing two No. 12 copper conductors has a maximum overcurrent protection of
    7·2 answers
  • Amy has decided to use a dark background and light colored text for her prensentation. Which toolbar option will let her change
    5·1 answer
  • In an oligopolistic market, consumer choice is?
    12·2 answers
  • Hi! I'm Kayla! I was wondering who does homework on the weekends... anybody?? I guess almost everyone, including me. Anyways, le
    13·2 answers
  • Why does dew form on grass overnight
    7·1 answer
  • identify at least three additional ethical responsibilities expected from a computer professional. In brief, explain each respon
    11·1 answer
  • Which of the following activities does an effective team do?
    15·2 answers
  • I’m gonna ask this again because I REALLY need an answer.
    10·2 answers
  • When dividing it’s total debt by total equity what’s a company trying to measure
    9·1 answer
  • Explain why the receptionist responded as indicated in the following scenario.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!