User:Sakti123

/*2. Array addition Write a program to accept two arrays of alphabets and combine the arrays as per the input flag – “merge”, “append”, “common” If “merge” is given, create the result array with {<1st element in 1st array>, <1st element in second array>,<2nd element in first array>, <2nd element in second array>…….,,} If “append” is given, the result array appending second array to the end of first array If “common” is given, the result array should only have elements common in both arrays. */

public class Arrayaddition { public static int[] addArray(int[] a,int[] b,String func) {       int len=a.length+b.length,i; int[] result=new int[len]; int flag=3; if(func.equals("merge")) flag=0; if(func.equals("append")) flag=1; if(func.equals("common")) flag=2; switch(flag) {       case 0: result=merge(a,b); break; case 1: result=append(a,b); break; case 2: result=common(a,b); int[] result1=new int[result[0]-1]; for(i=0;ij) {         while(k<j) {           result[l]=a[k]; result[l+1]=b[k]; l+=2; k++; }         while(l<(i+j)) {           result[l]=a[k]; l++; k++; }       }      else {        while(k<i) {           result[l]=a[k]; result[l+1]=b[k]; l+=2; k++; }     }          return result; }        public static int[] append(int[] a,int[] b)         { int len=a.length+b.length; int i=0,j=0; int[] result=new int[len]; while(ic[j+1]) {                c[j]=c[j]+c[j+1]; c[j+1]=c[j]-c[j+1]; c[j]=c[j]-c[j+1]; }            }           }         l=1; for(i=0;i<c.length-1;i++) {             for(j=i+1;j<c.length;) {               if(c[i]==c[j]) {                 j++; }               else {                 d[l]=c[i]; i=j++; l++; }             }            }            d[0]=l; return d;        } } /*3.Batch grade Write a program to calculate the exam pass percentage of a batch consisting of 4 students (each having 5 marks entered in order) based on the following rule. Weigtage of mark1, mark2 is 25% Weightage of mark3, mark4 is 20% Weightage of mark5 is 10% Maximum marks is 100 for each subject. Batch grade is A if, batch percentage is above 80% and B if between 40% and 80% and C if less than 40% If a student didn’t appear for an exam(that is marks = 0), then his other marks should not be considered for the batch grade calculation */

public class BatchGrade { public static void calcGrade(double arr[][]) {   double[] mark={0,0,0,0}; char[] grade=new char[4]; int i=0,j=0; for(i<4;i++) {     for(j=0;j<5;j++) {       if((j==0 || j==1) && arr[i][j]<=100) mark[i]+=.25*arr[i][j]; if((j==2 || j==3) && arr[i][j]<=100) mark[i]+=.2*arr[i][j]; if(j==4 && arr[i][j]<100) mark[i]+=.1*arr[i][j]; }   }    for(i=0;i<4;i++) {     for(j=0;j<5;j++) {       if(mark[i]>80 && arr[i][j]!=0) grade[i]='A'; else if(mark[i]>40 && arr[i][j]!=0) grade[i]='B'; else if(arr[i][j]!=0) grade[i]='C'; else grade[i]='F'; }   }     for(i=0;i<4;i++) {     System.out.print(i+1 +" Student"); if(grade[i]!='F') System.out.print("\t" +grade[i]); else System.out.print("\t" +"Not considered for evaluation"); System.out.println(" "); } } } /* 1. Favorite tasks Write a program to store the names of favourite tasks (say ‘painting’, ‘reading’, ‘writing’…..) * and return the string “My favourite tasks are, , ,…..and .” (tasks listed in ascending order). */

public class Favourite { public static String writefavourite(String[] task) {   int i=0,j,k,l; int len=task.length; String res="My favourite tasks are "; for(i=0;itask[j].charAt(l)) {          String tmp=task[i]; task[i]=task[j]; task[j]=tmp; l=k; }        else if(task[i].charAt(l)<task[j].charAt(l)) l=k; else l++; }     }    }       i=0; while(i<len-1) {     res=res.concat(task[i] +"," +" "); i++; }   res=res.concat("and " +task[i]); return res; } }