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
Semmy [17]
3 years ago
14

Create a Java program that takes a list of integers as input from the user and outputs whether the list contains all even number

s, odd numbers, or neither. The input begins with the number of integers that will be stored in the list followed by the numbers to be stored in the array.
Computers and Technology
1 answer:
garik1379 [7]3 years ago
6 0

Answer:

This question is answered in Java programming language

import java.util.Scanner;

public class Main{

   public static void NumberTypes(int[]myarray){

       int evennum = 0; int oddnum = 0;

       for(int i = 1;i<=myarray[0];i++){

           if(myarray[i]%2==0){                evennum++;}

           else{                oddnum++;}

       }

   if(evennum == 0 && oddnum!=0){    System.out.print("Odd List");    }

   else if(evennum != 0 && oddnum==0){        System.out.print("Even List");    }

   else if(evennum != 0 && oddnum!=0){        System.out.print("None");    }

   }    

public static void main(String [] args){

int num;

Scanner input = new Scanner(System.in);

System.out.print("Length of list: ");

num = input.nextInt();

int [] myarray = new int[num+1];

myarray[0] = num;

for(int i = 1;i<num+1;i++){

myarray[i] = input.nextInt();

}

NumberTypes(myarray);

}

}

Explanation:

This question is answered in Java and it uses function to answer the question.  

The name of the function is NumberTypes

The program starts here

import java.util.Scanner;

public class Main{

The function NumberTypes starts here

   public static void NumberTypes(int[]myarray){

This line initializes even and odd to 0

       int evennum = 0; int oddnum = 0;

The following iteration iterates through the array

       for(int i = 1;i<=myarray[0];i++){

This checks if current array element is even. If yes, even variable is incremented by 1

           if(myarray[i]%2==0){                evennum++;}

This checks if current array element is odd. If yes, odd variable is incremented by 1

           else{                oddnum++;}

       }

If even is 0 and odd is not 0. The list is purely even number

   if(evennum == 0 && oddnum!=0){    System.out.print("Odd List");    }

If odd is 0 and even is not 0. The list is purely odd number

   else if(evennum != 0 && oddnum==0){        System.out.print("Even List");    }

If even and odd are not 0. The list is purely neither even nor odd  

   else if(evennum != 0 && oddnum!=0){        System.out.print("None");    }

   }    

The main method begins here

public static void main(String [] args){

This declares num; the length of array as integer

int num;

Scanner input = new Scanner(System.in);

This prompts the user for length of the array

System.out.print("Length of list: ");

This gets the length of the array

num = input.nextInt();

This declares the array as integer

int [] myarray = new int[num+1];

This initializes index 0 as the length of the array

myarray[0] = num;

The following iteration gets input for the array

<em>for(int i = 1;i<num+1;i++){ </em>

<em>myarray[i] = input.nextInt(); </em>

<em>} </em>

This calls the function

NumberTypes(myarray);

}

}

You might be interested in
What is the output of the following program?
Contact [7]

The question is poorly formatted:

<em>#include <stdio.h> </em>

<em>int main() { </em>

<em>int arr [5] = {1, 2, 3, 4, 5}; </em>

<em>arr [1] = 0; </em>

<em>arr [3] = 0; </em>

<em>for (int i = 0;i < 5; i+=1) </em>

<em>printf("%d", arr[i]); </em>

<em>return 0; </em>

<em>}</em>

Answer:

The output is 10305

Explanation:

I'll start my explanation from the third line

This line declares and initializes integer array arr of 5 integer values

<em>int arr [5] = {1, 2, 3, 4, 5}; </em>

<em />

This line sets the value of arr[1] to 0

<em>arr [1] = 0; </em>

<em>At this point, the content of the array becomes arr [5] = {1, 0, 3, 4, 5};</em>

This line sets the value of arr[3] to 0

<em>arr [3] = 0; </em>

<em>At this point, the content of the array becomes arr [5] = {1, 0, 3, 0, 5};</em>

<em />

The next two lines is an iteration;

The first line of the iteration iterates the value of i order from 0 to 4

<em>for (int i = 0;i < 5; i+=1) </em>

<em />

This line prints all elements of array arr from arr[0] to arr[4]

<em>printf("%d", arr[i]); </em>

<em />

<em>So, the output will be 10305</em>

3 0
3 years ago
A local router is configured to limit the bandwidth of guest users connecting to the Internet. Which of the following best expla
mariarad [96]

Answer:

The correct option is d. Guest users will be restricted in the maximum amount of data that they can send and receive per second.

Explanation:

Bandwidth can be described as the maximum data transfer that an internet connection or a network has. It gives a measure of the amount of data that can be transmitted over a particular connection in a particular amount of time. For instance, the capacity of a gigabit Ethernet connection is 1,000 megabits per second (Mbps) (which also translates to 125 megabytes per second).

Therefore, when a local router is configured to limit the bandwidth of guest users connecting to the Internet, it will restrict the the maximum amount of data that they can transmit per second.

Therefore, the correct option is d. Guest users will be restricted in the maximum amount of data that they can send and receive per second.

3 0
3 years ago
The role of a computer-based instructional system is to deliver messages to learners. Those messages originated from a human tut
zalisa [80]

Answer:

True.

Explanation:

A computer system is digital device which comprises of a hardware and a software components. The hardware is the physical parts of the system while the software is the written instructions that controls the hardware.

The computer is a part of the information system which also includes the procedure and user. It is used to communicate between users in a network with ease. The computer based instructional system is an information systems used in educational facilities. They help teachers pass across information to the students and provides a platform for student to share their resources and seek solutions where necessary.

3 0
4 years ago
A ____ is harmful computer code that spreads without your interaction, slipping from one network to another and replicating itse
blondinia [14]
Malware is the answer

3 0
4 years ago
What happens to the files and folders on the desktop when the computer is turn off
andriy [413]

Answer:

All of the files are stored on a hard-drive. Except for the files you just viewed before turning off the computer, which is stored in the RAM (Random Access Memory). If your computer is a desktop, and the power goes out while looking at a photo/pdf, you may corrupt/lose the image if the computer didn't have enough time to store it in the hard drive. Everything in the hard drive is 'scratched' into it like a record. If you delete a file, that part of the disk is 'smoothed' as best as it can. If you upload another file, you might corrupt/ruin the image/pdf. Think of the smoothing like recording a football game over an old VHS of Winne the Pooh. If you have any other questions, please ask by commenting on this answer!

4 0
3 years ago
Other questions:
  • Sam wants to move across the text in his documents to add data at predefined stops. Which key will he use to navigate through th
    13·2 answers
  • What are the names of each devices pleaseee​
    13·2 answers
  • Paulene is using this table in Word,and she started with the cursor in the box that read “Flavor”. she then hits Alt+End,The the
    7·1 answer
  • Which of the following statements is true?
    10·1 answer
  • Hi i need to know how much watt hours divided by month total
    14·1 answer
  • PLEASE HELP!!! History abounds with instances in which the work of scientists and artists were affected by the political, religi
    9·1 answer
  • Why does my inbox keep getting notifications and then disappearing?
    15·2 answers
  • 1. Define what grasslands are ?
    14·2 answers
  • Lucy wants to add some notes in her research paper that provide additional information to the reader. She also wants to display
    14·1 answer
  • What is the current situation of drone technology in emergency rescue and recovery
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!