Advertisements
Advertisements
Question
Write a program to accept a name and total marks of N number of students in two single subscript array name[] and totalmarks[].
Calculate and print:
- The average of the total marks obtained by N Number of students.
[average = (sum of total marks of all the students)/N] - Deviation of each student’s total marks with the average
[deviation = total marks of a student – average]
Solution 1
import java.io.*;
import java. util. Scanner;
class NameMarks {
public static void main(String argsO) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter number of students:”);
int N = sc.nextlnt( );
String named = new String[N];
int totalmarksG = new int[N];
double deviation[ ] = new double[N];
double sum = 0;
for (int i = 0; i < N; i+ +) {
System.out.print(“Enter Name of the Student:”);
name[i] = sc.next( );
System.out.print(“Enter Marks:”);
totalmarks[i] = sc.nextlntO;
sum = sum + totalmarks [i];
}
double average = sum / N;
System.out.println(“The average of the total marks of ” +N+” number of students:” +average);
for (int i = 0; i < N; i+ +) {
deviadon[i] = total marks (i] – average;
System.out.println(“Deviation of” + name[i] + “s marks with the average:” +deviation[i]);
}
}
}
Solution 2
import java.util.*;
public class AQ5
{public static void main(String hh[])
{
Scanner ob = new Scanner(System.in);
int sum = 0, dev;
System.out.printIn("Enter the number of students");
int N = ob.nextInt();
String name[] = new String[N];
int[] tot = new int[N];
for (int i = 0; i < N; i++)
{System.out.println("**Student" + (i + 1) + "**");
System.out.print("Enter the name :");
name[i] = ob.next();
System.out.print("Enter the total :");
tot[i] = ob.nextInt();
sum = sum + tot[i];
}
int avg = sum / N;
System.out.printin("\n\nAverage of total marks of all the students: " + avg);
for (int j = 0; j < N; j++)
{
dev = tot[j] – avg;
System.out.print(name(j]);
System.out.printIn("Deviation = " + dev);
}
}}
APPEARS IN
RELATED QUESTIONS
What is the difference between the linear search and the binary search technique?
Name the following :
(i) A keyword used to call a package in the program.
(ii) Any one reference data type.
Differentiate between searching and sorting.
Using the switch statement, write a menu driven program to:
(i) To find and display all the factors of a number input by the user (including 1 and excluding number itself).
Example:
Sample Input: n=15
Sample Output: 1, 3, 5.
(ii) To find and display the factorial of a number input by the user (the factorial of a non-negative integer n, denoted by n\ is the product of all integers less than or equal to n.
Example:
Sample Input: n=5
Sample Output: 5! = 1×2×3×4×5 = 120.
For an incorrect choice, an appropriate error message should be displayed.
Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.
int a = new int (5);
for (int i = 0; i < = 5; i++) a [i] = i;
Consider the given array and answer the question given below:
int x[ ] {4; 7,9,66,72,0,16);
What is the length of the array?
Consider the given array and answer the question given below:
int x[ ] {4; 7,9,66,72,0,16);
What is the value in x[4]?
Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in ascending order. Display the sorted array and original array.
Define a class to accept values into an array of double data type of size 20. Accept a double value from user and search in the array using linear search method. If value is found display message "Found" with its potiition where it is present in the array. Otherwise display message "not found".
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found” using Binary search technique.
5.6, 11.5, 20.8, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.