Hello!
Declaration of array in java
Arrays are the objects in the Java , array stores number of single type data in contagious manner
type_name variable_name []
EX: int test[];
Allocating memory to array
var_name = new type[SIZE]
Ex: test = new int[50]
// initializing array
var_name = new type[]{d1,d2,d3}
Ex: test = new int[]{1,2 ,5}
// accesing array elements
Basically array index strarts from 0
so test = new int[]{1,2,3}
test[0] is 1
test[1] is 2
test[2] is 3
LOGIC:
CODE:
import java.util.Scanner;
class ArrayProcessing
{
public static void main(String args[])
{
// test is 100 rows 100 colums array stores 100 test marks of 100 students each
int test[][]=new int[100][100];
// count stores number of students in the test
int count[] = new int[100];
// average stores average of all the tests
double avg[] = new double[100];
// stores the percentage of students who scores above average
double percent[] = new double[100];
// total , avg count are temporary varibales
int total,avgCount;
Scanner sc=new Scanner(System.in);
// asks the user to enter the number of test cases
System.out.println("Enter the number of Test cases: ");
int N=sc.nextInt();
// for loop for number of tests
for(int i=0;i<N;i++)
{
// ask the user to enter marks of test i
System.out.println("Enter the array elements for case: "+(i+1));
// initially total of test i is 0
total = 0;
// initially number of marks in the test is 0
count[i] = 0;
// for loop for each marks in the i th test
for(int j=0;j<100;j++)
{
// gets the j th marks of ith test
int k=sc.nextInt();
// if enter marks is -1 the breaks the for loop
if(k == -1)
break;
// if not then stores the marks in the test
test[i][j]=k;
// adds the entered marks to total
total +=k;
// counts the number of marks entered
count[i]++;
}
// calculates the average of the i th test
avg[i] = total/count[i];
avgCount = 0;
// iterates over each marks in i th test and if marks > avg marks
// then increments the avgCount
for(int k=0;k<count[i];k++)
if(test[i][k] >= avg[i])
avgCount++;
// calculates the percentage of the students having more than average
percent[i] = (avgCount*100/count[i]);
}
for(int i=0;i<N;i++)
// displays the avg of the test i and percentage
System.out.println("case #"+(i+1) + ": " + Math.round(avg[i]) + " " + Math.round(percent[i])+"%");
}
}
OUTPUT:
Hope this helps and clear.
Please feel free to comment if you have any doubts . If you face any difficulty please let me know i will help you with in few minutes.
I strive to provide the best of my knowledge so please upvote if you like the content.
Thank you!
Java code ABOVE AVERAGE 40 Input Standard input Output Standard output Topic Array & Array Processing...
Java code INNER PRODUCT 4E Input Standard input Output Standard output Topic Array & Array Processing! Problem Description The inner product (also known as the dot product or scalar product) of the elements of set A and the elements of set B of size is defined as the sum of the products of corresponding terms. For example, given set A as the array (2, 3, 4, 5, 6, 7, 8, 9; and set B as 6,5, 4, 3, 2, 7,...
Java code COCONUT KELAPA4 4A. Input Standard input Output Standard output Topic Array & Array Processing Problem Description Ali Wali owns a coconut plantation and a number of monkeys for bringing down coconuts. Every day, Ali would record the number of coconuts brought down by his monkeys. At the end of a certain time period, he would determine from the data recorded, the lowest and the highest number of coconuts as well as their number of occurrences. Write a program...
Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing Birthday Graph Problem Description Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social E interaction among co-workers, foster friendship among classmates or even strengthen bond between E BOBO Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, UU candles with names, or it can be in the form of simple bar...
C Programming Language The code below matches the sample input/output but is marked wrong. Are there other ways to do this problem? The focus is on recursion and functions. #include<stdio.h> int joCheck(unsigned long long int number) { if(number % 7 == 0 || number % 8 == 0) { return 1; } else return 0; } int main() { int cases = 0; scanf("%d", &cases); for(int i = 1; i<=cases; i++) { unsigned long long int number; scanf("%d", &number); if(joCheck(number)...
Code with Java using arrays and Scanner only ( input should end with 0 to terminate the program) Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social interaction among co-workers, foster friendship among classmates or even strengthen bond between families. Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, candles with names, or it can be in the form of simple bar chart to indicate the birthday...
In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...
Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...
Given an array A[] of integers find sum of product of all pairs of array elements Input: First line consists of T test cases. First line of every test case consists of N, denoting number of elements of array. Second line consists of elements of array. Output: Single line output, print the sum of products. Constraints: 1<=T<=100 1<=N<=100 Solve the problem using pointers and (if possible) using operators Example: Input: 2 3 1 3 4 4 2 3 4 5...
Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below. For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1. Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS], int...
Using JAVA, write an application that uses an Array of 30 Numbers (random integers from 1 - 100) and returns the maximum number, minimum number, average of all numbers, and prints a Bar Chart to show the number distribution (1-9, 10-19,20-29, …80-89, 90-100). Note; maximum number, minimum number, average number, and the Bar Chart must use implemented as separate methods in a separate class. Method call should pass an array as an argument. Methods should accept an array as an...