# One Dimensional Array (Exercises, Practice)Exercises.

Tue Apr 20 2021 23:31:02 GMT+0000 (Coordinated Universal Time)

Saved by @ahmedqgqgq #java

```//Arrays (one_Dimensional Arrays)
/*
Write a java program to sum values of an array.
*/
public class Amazon {
public static void main(String[] args) {
int ahmedarr[] = { 1, 5, 8, 9 };
int sum = 0;
for (int i = 0; i < ahmedarr.length; i++) {
sum = sum + ahmedarr[i];
}
System.out.println("The Sum=" + sum);
}
}
//Arrays (one_Dimensional Arrays)
/*
Write a java program to sum values of an array.
*/
public class Amazon {
public static void main(String[] args) {
int ahmedarr[] = { 1, 5, 8, 9 };
int sum = 0;
for (int i = 0; i < ahmedarr.length; i++) {
sum = sum + ahmedarr[i];//sum+=ahmedarr[i];
}
System.out.println("The Sum=" + sum);
}
}
import java.util.Scanner;
/*
Write a Java program to calculate:
the average value of array elements.
*/
public class Amazon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter size number:");
int size = input.nextInt();
int arrnumber[] = new int[size], sum = 0;
for (int i = 0; i < arrnumber.length; i++) {
arrnumber[i] = input.nextInt();
}
for (int j = 0; j < arrnumber.length; j++) {
sum += arrnumber[j];
}
System.out.println("The Average =="+(sum/size));
}
}
import java.util.Scanner;
/*
Write a Java program to calculate:
the average value of array elements.
*/
public class Amazon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter size number:");
int size = input.nextInt();
int arrnumber[] = new int[size], sum = 0;
for (int i = 0; i < arrnumber.length; i++) {
arrnumber[i] = input.nextInt();
}
for (int j = 0; j < arrnumber.length; j++) {
sum += arrnumber[j];
}
System.out.println("The Average ==" + (sum / size));
//can double
}
}
import java.util.Scanner;
/*
Write a Jave program to test:
if an array contains a specific Value
*/
public class Amazon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the specific num:");
int num = input.nextInt();
System.out.println("Enter the size:");
int size = input.nextInt();
int ahmed[] = new int[size];
System.out.println("Enter the array values:");
for (int i = 0; i < size; i++) {
ahmed[i] = input.nextInt();
}
boolean f = false;
for (int i : ahmed) {
if (num == i) {
f = true;
break;
}
}
System.out.println("array contains a specific value?");
if (f) {
System.out.println("Found");
} else {
}
}
}
/*
Write a Jave program to test:
if an array contains a specific Value
*/
public class Amazon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the specific num:");
int num = input.nextInt();
System.out.println("Enter the size:");
int size = input.nextInt();
int ahmed[] = new int[size];
System.out.println("Enter the array values:");
for (int i = 0; i < size; i++) {
ahmed[i] = input.nextInt();
}
boolean f = false;
for (int i : ahmed) {
if (num == i) {
f = true;
break;
}
}
System.out.println("array contains a specific value?");
if (f) {
System.out.println("Found");
} else {
}
}
}
import java.util.Scanner;
/*
Write a Java program to find the maximum
and minimum value of an array.
*/
public class Amazon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the size:");
int size = input.nextInt();
int ahmedarr[] = new int[size];
System.out.println("Enter the array elements:");
for (int i = 0; i < ahmedarr.length; i++) {
ahmedarr[i] = input.nextInt();
}
int minimum = ahmedarr[0], maxmum = ahmedarr[0];
for (int i = 1; i < ahmedarr.length; i++) {
if (ahmedarr[i] < minimum) {
minimum = ahmedarr[i];
}
if (ahmedarr[i] > maxmum) {
maxmum = ahmedarr[i];
}
}
System.out.println("Minimum value==" + minimum);
System.out.println("Maxmum value==" + maxmum);
}
}
/*
Write a Java program to find the maximum
and minimum value of an array.
*/
public class Amazon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the size:");
int size = input.nextInt();
int ahmedarr[] = new int[size];
System.out.println("Enter the array elements:");
for (int i = 0; i < ahmedarr.length; i++) {
ahmedarr[i] = input.nextInt();
}
int minimum = ahmedarr[0], maxmum = ahmedarr[0];
for (int i = 1; i < ahmedarr.length; i++) {
if (ahmedarr[i] < minimum) {
minimum = ahmedarr[i];
}
if (ahmedarr[i] > maxmum) {
maxmum = ahmedarr[i];
}
}
System.out.println("Minimum value==" + minimum);
System.out.println("Maxmum value==" + maxmum);
}
}
import java.util.Arrays;
import java.util.Scanner;
/*
Write a Java program to sort a numeric array.
*/
public class Amazon {
public static void main(String[] args) {
int ahmedarray[] = { 1, 2, 3, 4, 5, 6, 7, 8, -9 };
Arrays.sort(ahmedarray);//arrangement
for (int i = 0; i < ahmedarray.length; i++) {
System.out.print(ahmedarray[i] + " ");
}
}
}//Arrays sort()arrangement.

```
content_copyCOPY