Question

Write a Java program to prompt for inputting an integer N, then enter N integers (a...

Write a Java program to prompt for inputting an integer N, then enter N integers (a loop is needed), print the numbers user entered, and the amount of even and odd numbers (zero is even number).

(1) Prompt for the user to input an integer and output the integer. (1 pts)

Enter an integer:

You entered:  5

(2) Prompt for the user to input N integers, output the numbers entered and the amount of even and odd numbers (9 pts)

Enter an integer:

You entered: 5

Enter 5 integers:

You entered: 
55 32 0 4  -9

3 even numbers and 2 odd numbers
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

CODE:-


import java.util.*;
public class Main{

public static void main(String []args){
Scanner sc=new Scanner(System.in); //declaring scanner to take input.
int number; //declaring number variable of integer type.
System.out.println("Enter an integer:\n");   
number=sc.nextInt(); //Taking number of number as input.
System.out.println("you entered:"+number);
System.out.println("Enter"+number+"numbers:");
int[] num=new int[number]; //declaring num array
int evenno=0,oddno=0;
for(int i=0;i<number;i++) //for loop to take n number of input.
{num[i]=sc.nextInt();
if(num[i]%2==0) //checking the number is even or odd.
evenno++; //if divisible by 2 increment evenno by one.
else
oddno++; //if not divisible by 2 increment oddno by one.
}
System.out.println("You entered:");
for(int i=0;i<number;i++)
{System.out.print(num[i]+" ");
  
}
System.out.println("");
System.out.println(evenno+" even numbers and "+oddno+" odd numbers"); }
}

CODE SCREENSHOT:-

OUTPUT SCREENSHOT:-

Add a comment
Know the answer?
Add Answer to:
Write a Java program to prompt for inputting an integer N, then enter N integers (a...
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 that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • Write a program in Java language to prompt the user to enter 3 integers (A, B,...

    Write a program in Java language to prompt the user to enter 3 integers (A, B, and C) then display these numbers from the lowest to the highest (sorted ascendingly) . Note that there are 6 different cases to handle proper order. As an example, a user entered 10 for A, 5 for B and 14 for C: the output of the program should look like this Enter number A? 10 Enter number B? 5 Enter number C? 14 Your...

  • Write a program that prompts the user for positive integers, only stopping when a negative integer...

    Write a program that prompts the user for positive integers, only stopping when a negative integer or zero is given. The program should then print out how many of the positive integers were odd. Example: Enter a positive integer (0 or negative to stop): 9 Enter a positive integer (0 or negative to stop): 4 Enter a positive integer (0 or negative to stop): 7 Enter a positive integer (0 or negative to stop): -3 You entered 2 odd integers....

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Complete the Python program below that performs the following operations. First prompt the user to input...

    Complete the Python program below that performs the following operations. First prompt the user to input two integers, n and m. If n<m, then print the odd positive integers that are less than m (in order, on a single line, separated by spaces). If man, then print the even positive integers that are less than n (in order, on a single line, separated by spaces). If neem, then print nothing. For instance, if the user enters 5 followed by 10,...

  • Using java prompt the user to enter an integer called n. Then scan in n values...

    Using java prompt the user to enter an integer called n. Then scan in n values of type double.Find the middle value of the n numbers using a for loop. Assume the middle value is the ((n+1)/2) th number entered.

  • 1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or **...

    1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or ** 2. Prompt the user for two input integers ('a' and'b') 3. The input numbers can be positive or negative 4. Perform the arithmetic operation using the two input numbers 5. The first entered number ('a') is the left side, the second ('b') the right side of the operation For exponentiation, the first number is the base, the second the exponent Print (display) the following...

  • In Java - Write a program that prompts the user to enter two integers and displays...

    In Java - Write a program that prompts the user to enter two integers and displays their sum. If the input is incorrect, prompt the user again. This means that you will have a try-catch inside a loop.

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • 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...

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