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
java programe Write a program that prompts the user to enter in an integer number representing...
Write a Java program that prompts the user to enter a number representing a geometric shape. Options are 1 for square, 2 for rectangle, and 3 for right triangle. According to the user input, the program will collect either 1, 2 or 3 values from the user representing the lengths of the shape sides. The user is responsible for ensuring the 3 sides of the triangle represent a right triangle. The program will print the perimeter of the shape. Use...
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 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 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 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 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”
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)...
Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....
Write a java program that uses a loop to input, from the user not using gui, a collection of values that are the number of steps taken each day for a sequence of days and stores those amounts in an array. the array length should be 31, The user is not required to enter 31 values. the program determines and displays the largest number of steps for a single day, the smallest number of steps for a single day and...
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...