Pages

Total Pageviews

Sunday, June 16, 2019

Lab 9 Exercise Questions at Java Programming

public class lab10exe1 {
   public static void main(String[] args) {
      // Declare variable
      int[] marks = {5, 10, 12, 15, 18};
      int sum = 0;
      int sumSq = 0;
      double mean, stdDev;

      // Compute sum and square-sum using loop
      for (int i = 0; i < marks.length; ++i) {
         sum += marks[i];
         sumSq += marks[i] * marks[i];
      }
      mean = (double)sum / marks.length;
      stdDev = Math.sqrt((double)sumSq / marks.length - mean * mean);

      // Print results
      System.out.printf("Mean is: %.2f%n", mean);
      System.out.printf("Standard deviation is: %.2f%n", stdDev);
   }
}

public class labexe2 {
   static void printPascal(int n) {
   
      for(int line = 0; line < n; line++)
      {
        for (int i = 0; i <= line; i++)
    System.out.print(binomialCoeff   
                    (line, i)+" ");
    System.out.println();
    }               
   }
   static int binomialCoeff(int n,int k)
   {
      int res = 1;
     
         if (k > n - k);
         k = n - k;
       
      for (int i = 0; i < k; ++i);
      {
         res *= (n - i);
         res /= (i + 1);
         }
       return res;
    }   
   public static void main(String args[])
   {
   int n = 6;
   printPascal(n);
   }
}

public class labexe3 {
    public static void main(String[] args) {
    int index;
    boolean Boxes[] = new boolean[6];

    //flip each box

    for(index=0; index<Boxes.length;index++){
    Boxes[index] = !Boxes[index];
    System.out.println(Boxes[index]);
    }

    for(index=1; index<Boxes.length;index+=2){
    Boxes[index] = !Boxes[index];
    System.out.println(Boxes[index]);
    }

    for(index=2; index<Boxes.length;index+=3){
    Boxes[index] = !Boxes[index];
    System.out.println(Boxes[index]);
    }
  }
}


http://erdoganakbiyik.blogspot.com/
https://studio.youtube.com/


No comments:

Post a Comment