Question

Write a program that prompts the user to enter injava programe

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

Arrays.java

import java.util.Scanner;


public class Arrays {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.print("Enter the array size: ");
       int n = scan.nextInt();
       int a[] = new int[n];
       for(int i=0; i<a.length; i++){
           System.out.print("Enter the element: ");
           a[i]=scan.nextInt();
       }
       System.out.println("The array elements on single line: ");
       for(int i=0; i<a.length; i++){
           System.out.print(a[i]+" ");
       }
       System.out.println();
       System.out.println("The array elements in reverse: ");
       for(int i=a.length-1;i>=0; i--){
           System.out.print(a[i]+" ");
       }
       System.out.println();
       System.out.println("Even numbers in array are: ");
       for(int i=0; i<a.length; i++){
           if(a[i]%2 ==0)
           System.out.print(a[i]+" ");
       }
       System.out.println();
       System.out.println("Even index elements in array are: ");
       for(int i=0; i<a.length; i+=2){
           System.out.print(a[i]+" ");
       }
       System.out.println();
      
       System.out.print("Enter the number that to be searched in an array: ");
       int search = scan.nextInt();
       int count = 0;
       for(int i=0; i<a.length; i++){
           if(a[i] == search){
               count++;
           }
       }
   System.out.println("Number of occurances in ann array is "+count);
   }

}

Output:

Enter the array size: 5
Enter the element: 1
Enter the element: 2
Enter the element: 3
Enter the element: 4
Enter the element: 5
The array elements on single line:
1 2 3 4 5
The array elements in reverse:
5 4 3 2 1
Even numbers in array are:
2 4
Even index elements in array are:
1 3 5
Enter the number that to be searched in an array: 3
Number of occurances in ann array is 1

Add a comment
Know the answer?
Add Answer to:
java programe Write a program that prompts the user to enter in an integer number representing...
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: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

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

  • I need to Write a test program that prompts the user to enter 10 double values...

    I need to Write a test program that prompts the user to enter 10 double values into an array, calls a method to calculate the average of the numbers, and displays the average. Next, write a method that returns the lowest value in the array and display the lowest number. The program should then prompt the user to enter 10 integer values into an array, calculates the average, and displays the average. The program should have two overloaded methods to...

  • Write a while loop in java that will let the user enter a series of integer...

    Write a while loop in java that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates.

  • Java Write a program that prompt the user to enter a decimal number representing the radius...

    Java Write a program that prompt the user to enter a decimal number representing the radius of a circle. If the number is greater or equal to zero, the program displays the area of the circle. Otherwise, the program displays “negative input”

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Task 1 : Write a Java program that prompts for and reads 10 integers from the...

    Task 1 : Write a Java program that prompts for and reads 10 integers from the user into an integer array of size 10, it then: - calculates the sum and average of positive numbers of the array and displays them. [Note: consider 0 as positive] Note: The program must display the message: "There are no positive values" if the array does not contain any positive value.

  • Write a program that prompts the user to enter a number within the range of 1...

    Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive. The program then generates a random number using the random class: If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number, If the users guess matches the random number tell them they win! If the users guess does not match the random number tell them they are wrong. Use a...

  • Write a program that prompts the user for a positive integer, n, and then prints a...

    Write a program that prompts the user for a positive integer, n, and then prints a following shape of stars using nested for loop, System.out.print(“*”);, and System.out.println();. Example1: Enter a positive integer: 3 * * * * * * * * * Example2: Enter a positive integer: 5 * * * * * * * * * * * * * * * * * * * * * * * * * JAVA LANGUAGE!!

  • Write a C program to do the following 1) request user to enter 10 integer into...

    Write a C program to do the following 1) request user to enter 10 integer into an array 2) sort the array in ascending order 3) display the sorted array 4) count the number of odd and even number in the array and print out the result 5) add the value of the odd number and even number and calculate the average of the odd and even number. display the result 6) write function addNumber() to add all the number...

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