Bonafide record of work done by of
_ in during even/odd semester in
academic year
Staff In-charge Head of the Department
Submitted to the practical Examination held at Kalasalingam University, Krishnankoil on
REGISTER
NUMBER
Internal Examiner External Examiner
, EXPERIMENT EVALUATION SUMMARY
Name: Reg No:
Class: Faculty:
Marks Faculty
S.No Date Experiment (10) Signature
1
2
3
4
5
6
7
8
9
10
11
12
, Ex-1: Basic java Programs
1.Aim: To write a java program to find Mean and Standard deviation.
Algorithm:
Step 1 - START
Step 2 - Declare a double array namely input_array, two doube values namely sum and
standard_deviation.
Step 3 - Read the required values from the user/ define the values.
Step 4 - Compute ∑(Xi - ų)2 / N and store the value in result variable.
Step 5 - Display the result
Step 6 – Stop
Source code:
public class StandardDeviation {
public static void main(String[] args) {
double[] numArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double SD = calculateSD(numArray);
System.out.format("Standard Deviation = %.6f",SD);
}
public static double calculateSD(double numArray[]){
double sum = 0.0, standardDeviation = 0.0;
int length = numArray.length;
for(double num : numArray) {
sum += num; }
double mean = sum/length;
for(double num: numArray) {
standardDeviation += Math.pow(num - mean, 2); }
return Math.sqrt(standardDeviation/length);
, }
}
Output:
Standard Deviation=2.872281
Algorithm(Mean):
Step1:Take an integer set A of n values.
Step2:Add all values of A together.
Step3:Divide result of Step 2 by n.
Step4:The result is mean of A's values.
Step5:end of the program.
Source Code:
public class CaculatingMean {
public static void main(String args[]){
float mean;
int sum, i;
int n = 5;
int a[] = {2,6,7,4,9};
sum = 0;
for(i = 0; i < n; i++)
{
sum+=a[i];
}
System.out.println("Mean ::"+ sum/(float)n); }
}
Output:
C:\Users\u\OneDrive\disktop>javac CaculatingMean.java
C:\Users\u\OneDrive\disktop>java CaculatingMean
Mean ::5.6
,2.Aim: write a java program to print the given pattern(number and character).
Algorithm:
Step1:Read the value of n.
Step2:Declare the pattern what we want to print using 2 for loops.
Step3:display the same pattern.
Step4:Stop the program.
Source Code:
class Characterpattern
{
public static void pyramidPattern(int n) {
for (int i=0; i<n; i++) {
for (int j=n-i; j>1; j--) {
System.out.print(" "); }
for (int j=0; j<=i; j++ ) {
System.out.print("* "); }
System.out.println(); }
}
public static void main(String args[])
{
int n = 5;
pyramidPattern(n);
Output:
C:\Users\u\OneDrive\disktop>javac Characterpattern.java
C:\Users\u\OneDrive\disktop>java Characterpattern
, *
**
***
****
*****
Algorithm:
Step1:Read the value of n.
Step2:Declare the pattern what we want to print using 2 for loops.
Step3:display the same pattern.
Step4:Stop the program.
Source Code:
public class Pyramidnumber
{
public static void main(String[] args){
int rows = 6;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j < i; j++){
System.out.print(" ");}
for (int j = i; j <= rows; j++) {
System.out.print(j+" "); }
System.out.println(); }
}
}
3.Aim:write a java program to find the second and third maximum number in an array
Algorithm:
Step1:Read the values of array
Step2:First, iterate through the array and find maximum.
Step3:Store this as first maximum along with its index.
Step4:Now traverse the whole array finding the second max, excluding the maximum element.
Step5:Finally traverse the array the third time and find the third largest element i.e., excluding
the maximum and second maximum.
Source Code:
public class Array
{
public void getMax( double ar[] )
{
double max1 = ar[0];
double max2 = ar[0];
double max3 = ar[0];
int ZERO = 0;
for( int i = 0; i < ar.length; i++ )
{
if( ar[i] >= max1){
max1 = ar[i];
ZERO = i;
4.Aim: write a java program to find ncr,npr
Algorithm:
Step1:Read the values of n and r.
Step2:calculate the factorial of n ,rand n- r.
Step3:calculate the ncr using the formula (fact(n)) / (fact(r)*fact(n-r)) store the result in ncr.
Step4:Display the ncr.
Step5:stop the program.
Source Code:
import java.util.Scanner;
public class CodesCracker{
public static void main(String[] args) {
int n, r, ncr;
Scanner s = new Scanner(System.in);
System.out.print("Enter the Value of n: ");
n = s.nextInt();
System.out.print("Enter the Value of r: ");
r = s.nextInt();
ncr = (fact(n)) / (fact(r)*fact(n-r));
System.out.println("\nnCr = " +ncr);
}
public static int fact(int num)
{
int fact=1;
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller prasadvhari300. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $9.99. You're not tied to anything after your purchase.