0% found this document useful (0 votes)
18 views4 pages

Array Homework 2

The Java program contains multiple methods for array manipulation and analysis. It includes functionalities to print distinct numbers from an array, analyze user-input scores, generate random integers, and count occurrences of user-input integers. Each method utilizes loops and conditionals to perform its respective tasks and outputs results to the console.

Uploaded by

eyalprihar23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Array Homework 2

The Java program contains multiple methods for array manipulation and analysis. It includes functionalities to print distinct numbers from an array, analyze user-input scores, generate random integers, and count occurrences of user-input integers. Each method utilizes loops and conditionals to perform its respective tasks and outputs results to the console.

Uploaded by

eyalprihar23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

ArrayList;
import [Link];
import [Link];

public class ArrayHomework2 {

public static void main(String[] args) {

}
public static void PrintDistinctNum() {
int[] TenNum = {1, 2, 3, 2, 1, 6, 3, 4, 5, 2};
int[] DistinctNum = new int[10];
int count = 0;

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


boolean isDistinct = true;

for (int j = 0; j < i; j++) {


if (TenNum[j] == TenNum[i]) {
isDistinct = false;
break;
}
}

if (isDistinct) {
DistinctNum[count] = TenNum[i];
count++;
}
}

int[] distinctNumbers = [Link](DistinctNum,


count);
[Link]([Link](distinctNumbers));
}

public static void AnalyzeScores() {

Scanner scan = new Scanner([Link]);

ArrayList<Integer> Score = new ArrayList<>();


[Link]("Enter scores (enter -1 to
stop):");
int input = [Link]();
while (input != -1) {
[Link](input);
input = [Link]();

//int[] Score = {100, 90, 80, 60, 50, 69, 120, 100};
int sum = 0;
for (int j : Score) {
sum += j;
}
int Avg = sum/([Link]()-1);
int AboveOrEqualAvg = 0;
int BelowAvg = 0;

for (int j : Score) {


if (j >= Avg) {
AboveOrEqualAvg++;
} else {
BelowAvg++;
}

[Link](AboveOrEqualAvg + " numbers are


above or equal to average");
[Link](BelowAvg + " numbers are below
average");

public static void RandomInt () {

int[] numbers = new int[10];

for (int i = 0; i < 100; i++) {


int random = (int) ([Link]() * 10);
numbers[random]++;

[Link]([Link](numbers));
}

public static void CountOccurance() {

Scanner scan = new Scanner([Link]);

ArrayList<Integer> count = new ArrayList<>();

[Link]("Enter the integers between 1


and 100 (input 0 to stop):");
int input = [Link]();
while (input != -0) {
[Link](input);
input = [Link]();

}
[Link](count);
int[] occurance = new int[100];
int length = [Link]();

for (int i = 0; i < length; i++) {


for (int j = 0; j < [Link]; j++) {
if ([Link](i) == j) {
occurance[j]++;
}
}

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


if (occurance[i] == 1) {
[Link]("The number " + i + "
occured " + occurance[i] + " time");
}
else if (occurance[i] != 0) {
[Link]("The number " + i + "
occured " + occurance[i] + " times");
}
}
}

You might also like