Java Final Doc Rest 5
Java Final Doc Rest 5
2012
Submitted by:-Rohit Keshari Course:-Mtech(CSE)
Index
Sr.n Practical o
1
Signatu Remark re
Program no:-A
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class helloworld1 { public static void main(String args[]){ System.out.println("HELLO WORLD!"); System.out.println("WELCOME TO JAVA PROGRAMMING"); } }
Program no:-B
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class cheers2 { public static void main(String args[]){ for(int i=0;i<10;i++){ System.out.print("CHEERS!!!!"); System.out.print(" "); } } } Output of above program:-CHEERS!!!! CHEERS!!!! CHEERS!!!! CHEERS!!!! CHEERS!!!! CHEERS!!!! CHEERS!!!! CHEERS!!!! CHEERS!!!! CHEERS!!!! BUILD SUCCESSFUL (total time: 1 second)
Program no:-C
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class name3 { public static void main(String args[]){ System.out.println("My First name is :-Rohit"); System.out.println("My Last name is :-Keshari"); System.out.println("My age :-23"); System.out.println("My address is :-D140 new ashok nagar,new delhi"); } }
Output of above program:My My My My First name is :-Rohit Last name is :-Keshari age :-23 address is :-D140 new ashok nagar,new delhi
Program no:-1
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class numericTrangle4 { public static void main(String args[]){ int n=1,decre=5; while(n<7){ for(int i=decre;i>0;i--){ System.out.print(" "); } for(int j=1;j<n;j++){ System.out.print(j); System.out.print(" "); }
Program no:-2
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class trangleAlphabet5 { public static void main(String args[]){ int n=1,decre=5,alphae=65; char j; while(n<7){ for(int i=decre;i>0;i--){ System.out.print(" "); } for(j=65;j<alphae;j++){ System.out.print(j); } if(j!=66){ for(char z=(char)(j-2);z>=65;z--) System.out.print(z); } System.out.println(); n++; --decre; ++alphae; } }}
Program no:-3
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class trangleStar6 { public static void main(String args[]){ int n=1,decre=5,alphae=65; char j; boolean flag=false; while(n<7){ for(int i=decre;i>0;i--){ System.out.print(" "); } for(j=65;j<alphae;j++){ System.out.print("*"); if(flag==true) flag=false; else if((flag==false)&&(j<66)) flag=true; // System.out.print(" "); } if(!flag){ System.out.print(" "); for(char z=(char)(j-1);z>=65;z--) System.out.print("*"); ++alphae; } System.out.println(); n++; --decre; } }}
Program no:-4
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class trangleAlphabetWithSpace7 { public static void main(String args[]){ int n=1,decre=5,alphae=65; char j; boolean flag=false; while(n<7){ for(int i=decre;i>0;i--){ System.out.print(" "); } for(j=65;j<alphae;j++){ System.out.print(j); if(flag==true) flag=false; else if((flag==false)&&(j<66)) flag=true; } if(!flag){ System.out.print(" "); for(char z=(char)(j-1);z>=65;z--) System.out.print(z); ++alphae; } System.out.println(); n++; --decre; } }}
Program no:-5
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class rightSideTrangle8 { public static void main(String args[]){ int n=65,decre=5; char j; while(n<=70){ for( j=65;j<n;j++){ System.out.print(j); System.out.print(" "); } System.out.println(); n++; --decre; } }}
Program no:-6
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** *
* @author Amit */ public class triangularMultiplication9 { public static void main(String args[]){ int n=1,j; while(n<8){ for( j=0;j<n;j++){ System.out.print(j*n); System.out.print(" "); } System.out.println(); n++; } }}
6 8 12 10 15 20 12 18 24 30
Program no:-7
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class printSpacileCharacter10 { public static void main(String args[]){ int n=0; char j; while(n<2){ for( j=0;j<4;j++){ System.out.print("*"); } System.out.println(); for( j=0;j<4;j++){ System.out.print("#"); } System.out.println();
Program no:-8
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class factorial11 { public static void main(String args[]){ int n=10,j,fact=1; for( j=1;j<=n;j++){ fact*=j; } System.out.print(fact); } }
Program no:-9
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /**
* * @author Amit */ public class cubes12 { public static void main(String args[]) { int a; System.out.println("the cubes of numbers between 1 and 10."); for(int i=1;i<10;i++) { a=i*i*i; System.out.print(a); System.out.print(" "); } }}
Output of above program:the cubes of numbers between 1 and 10. 1 8 27 64 125 216 343 512 729
Program no:-10
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class Swap13 { public static void main(String args[]) { int a=5,b=7; System.out.println("Before swaping "+a+"and"+b); a+=b; b=a-b; a-=b; System.out.println("After swaping "+a+"and"+b); } }
Program no:-11
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class FtoC14 { public static void main(String args[]) { float f=69,c; c=(f-32)*(float)(5.0/9.0); System.out.println("69F into its equivalent centigrade temperature: "+c); } }
Program no:-12
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class Area15 { static double PI=3.14; public static void main(String args[]){ double r=10,a; a=PI*r*r; System.out.println("area of a circle (whose radius 10):"+a); } }
Program no:-13
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class sumofOddinteger16 { public static void main(String args[]) { int a=0; System.out.println("the SUM of ODD numbers between 1 and 99."); for(int i=1;i<=99;i++) { if(i%2!=0){ a+=i; } } System.out.print(a); System.out.print(" "); } }
Output of above program:the SUM of ODD numbers between 1 and 99. 2500
Program no:-14
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class operation17 { public static void main(String args[]) { double a=5.34,b=7.64; System.out.println("The two no. are "+a+" "+b); System.out.println("Addition of above two no. is:"+(a+b));
System.out.println("Subtraction of above two no. is:"+(a-b) ); System.out.println("Multiplication of above two no. is:"+(a*b) ); System.out.println("Devision of above two no. is:"+(a/b) ); } }
Output of above program:The two no. are 5.34 7.64 Addition of above two no. is:12.98 Subtraction of above two no. is:-2.3 Multiplication of above two no. is:40.797599999999996 Devision of above two no. is:0.6989528795811518
Program no:-15
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class Devision18 { public static void main(String args[]) { int m1=50,m2=70,m3=60,m4=67,m5=59,avg; avg=(m1+m2+m3+m4+m5)/5; if(avg>=60) System.out.println("First Devision"); if((avg<60)&&(avg>=45)) System.out.println("Second Devision"); if((avg<45)&&(avg>=33)) System.out.println("Third Devision"); if(avg<33) System.out.println("Fail"); } }
Program no:-16
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package labexercise; /** * * @author Amit */ public class ProfCourse19 { public static void main(String args[]) { int m=70,p=70,c=55; if((m>=60)&&(p>=50)&&(c>=40)){ if(((m+p+c)>=200)||((m+p)>=150)) System.out.println("Eligible candidates"); else System.out.println("Not eligible candidates"); } else System.out.println("Not eligible candidates");}}
Program no:-17
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class Season20 { public static void main(String args[]) { int i=2; switch(i){ case 1: case 2: case 12: System.out.println("Month Winter"); break; case 3: case 4: case 5: System.out.println("Month Spring"); break;
case 6: case 7: case 8: System.out.println("Month Summer"); break; case 9: case 10: case 11: System.out.println("Month Autumn"); break; default: System.out.println("Bogus Month"); }}}
Program no:-18
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; public class sort21 { public static void main(String args[]) { int s[]=new int[3],grater; Scanner sc= new Scanner(System.in); System.out.print("Enter the first trangle side value"); s[0]=sc.nextInt(); System.out.print("Enter the second trangle side value"); s[1]=sc.nextInt(); System.out.print("Enter the third trangle side value"); s[2]=sc.nextInt(); for(int j=0;j<3;j++) { for(int i=0;i<2;i++) { if(s[i]>s[i+1]) { grater=s[i]; s[i]=s[i+1]; s[i+1]=grater; }
Output of above program:Enter the first trangle side value5 Enter the second trangle side value7 Enter the third trangle side value2 257
Program no:-19
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; public class CharacterCount22 { public static void main(String args[]) { int len,count=1,z=1; String nstr; Scanner sc= new Scanner(System.in); System.out.println("Enter any string:"); nstr=sc.nextLine(); len=nstr.length(); char ch[]=new char[len+2],ch2[]=new char[len]; int lenOfChar[]=new int[len]; for(int i=0;i<len;i++){ ch[i]=nstr.charAt(i); } for(int j=0;j<len;j++){ for(int i=z;i<len;i++){ if(ch[i]==0) continue; if(ch[j]==ch[i]){ ++count; ch[i]=0; } } ++z;
ch2[j]=ch[j]; lenOfChar[j]=count; count=1; } for(int i=0;i<len;i++){ if(ch[i]==0) continue; System.out.println("Number of character "+ch2[i]+" comes "+lenOfChar[i]); }}}
Output of above program:Enter any string: ALLAHABAD Number of character Number of character Number of character Number of character Number of character
Program no:-20
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class Rectangle23 { Rectangle23(int a){ System.out.println("Squre area and area is--->"+a*a); } Rectangle23(int a,int b){ System.out.println("Rectangle area and area is--->"+a*b); } public static void main(String args[]) { Rectangle23 ob1; Rectangle23 ob2; ob1=new Rectangle23(5); ob2=new Rectangle23(6,7); }}
Output of above program:Squre area and area is--->25 Rectangle area and area is--->42
Program no:-21
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; public class sort21 { public static void main(String args[]) { int s[]=new int[3],grater; Scanner sc= new Scanner(System.in); System.out.print("Enter the first value"); s[0]=sc.nextInt(); System.out.print("Enter the second value"); s[1]=sc.nextInt(); System.out.print("Enter the third value"); s[2]=sc.nextInt(); for(int j=0;j<3;j++) { for(int i=0;i<2;i++) { if(s[i]>s[i+1]) { grater=s[i]; s[i]=s[i+1]; s[i+1]=grater; }} } for(int i=0;i<3;i++){ System.out.print(s[i]); System.out.print(" "); }}}
Output of above program:Enter the first value23 Enter the second value3 Enter the third value5 3 5 23
Program no:-22
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package labexercise; /** * * @author Amit */ import java.util.Scanner; public class CharacterCount22 { public static void main(String args[]) { int len,count=1,z=1; String nstr; Scanner sc= new Scanner(System.in); System.out.println("Enter any string:"); nstr=sc.nextLine(); len=nstr.length(); char ch[]=new char[len+2],ch2[]=new char[len]; int lenOfChar[]=new int[len]; for(int i=0;i<len;i++){ ch[i]=nstr.charAt(i); } for(int j=0;j<len;j++){ for(int i=z;i<len;i++){ if(ch[i]==0) continue; if(ch[j]==ch[i]){ ++count; ch[i]=0; } } ++z; ch2[j]=ch[j]; lenOfChar[j]=count; count=1; } for(int i=0;i<len;i++){ if(ch[i]==0) continue; System.out.println("Number of character "+ch2[i]+" comes "+lenOfChar[i]); }}}
Output of above program:Enter any string: rohit keshari Number of character Number of character Number of character Number of character Number of character Number of character Number of character r comes 2 o comes 1 h comes 2 i comes 2 t comes 1 comes 1 k comes 1
Program no:-23
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class Rectangle23 { Rectangle23(int a){ System.out.println("Squre area and area is--->"+a*a); } Rectangle23(int a,int b){ System.out.println("Rectangle area and area is--->"+a*b); } public static void main(String args[]) { Rectangle23 ob1; Rectangle23 ob2; ob1=new Rectangle23(5); ob2=new Rectangle23(6,7); } }
Output of above program:Squre area and area is--->25 Rectangle area and area is--->42
Program no:-24
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; import java.math.*; public class CompoundInterest24 { static double compound_annual(double amount,double interest,double yr){ double temp,compound_interest; temp=(interest/100)*100;
compound_interest=Math.pow((1+temp),yr); return compound_interest; } public static void main(String args[]){ double deposit_amount,interest_rate,yr,cp_ints,anual_basic; Scanner sc = new Scanner(System.in); System.out.println("Enter Deposit amount :"); deposit_amount=sc.nextDouble(); System.out.println("Enter Interest rate in percentage :"); interest_rate=sc.nextDouble(); System.out.println("Enter year :"); yr=sc.nextDouble(); cp_ints=compound_annual( deposit_amount,interest_rate,yr); System.out.println("The compound interest of given data is:-->"+cp_ints); anual_basic=deposit_amount*cp_ints; System.out.println("The anual basic pay of given data is:-->"+anual_basic); }}
Output of above program:Enter Deposit amount : 2345 Enter Interest rate in percentage : 2 Enter year : 2 The compound interest of given data is:-->9.0 The anual basic pay of given data is:-->21105.0
Program no:-25
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; class account{ int i; double old_amount; boolean b=false; boolean penality[]={false,false,false,false,false,false,false ,false,false,false}; String name[]={"ram","shyam","raju","om","ved","ravi", "rencho","saket","sudip","mahesh"}; int account_no[]={1125,1023,1650,2514,3621,1541,1198, 3012,1024,1107}; char type[]={'c','s','c','c','c','s','s','c','c','c'};
double bal[]={300012,102521.5,2012,3254.12,1201,8451.32, 5463,2541,3620.21,1405.32}; void deposit(int acct_no,double amount){ for(i=0;i<10;i++){ if(acct_no==account_no[i]){ old_amount=bal[i]; bal[i]+=amount; b=true; break;} //else // continue; } for_break:{ if(!b){ System.out.println("Sorry! "+acct_no+" Account number " + "not avalable here");break for_break;} System.out.println("Previous balance is:"+old_amount); System.out.println("Current balance is:"+bal[i]); if(penality[i]){ System.out.println("You have penality so 150Rs. deduted with your account"); bal[i]-=150; System.out.println("your current account balance"+bal[i]); } if(type[i]=='c') System.out.println("Account type is current therefore" + " threr is no any intrest"); else{ System.out.println("After 1yr balance" + " with interest is:"+bal[i]*Math.pow(1.75,1)); }}} void withdrawal(int acct_no,double ammount){ b=false; for(i=0;i<10;i++){ if(acct_no==account_no[i]){ old_amount=bal[i]; if(bal[i]>ammount) bal[i]-=ammount; else System.out.println("Not premissible! Your balance is low"); b=true; break;} } if(!b) System.out.println("Sorry! "+acct_no+" Account number" + "not avalable here"); if(bal[i]<500){ penality[i]=true;}}} public class Account_main25 { public static void main(String args[]){
int acct_no; double amount; char ch; Scanner sc=new Scanner(System.in); Scanner sc1=new Scanner(System.in); System.out.println("Enter account number"); acct_no=sc.nextInt(); System.out.println("Enter amount"); amount=sc.nextDouble(); System.out.println("w for withdraw"); System.out.println("d for deposit"); ch=sc1.findInLine(".").charAt(0); account obj = new account(); switch(ch){ case 'w': obj.withdrawal(acct_no, amount); break; case 'd': obj.deposit(acct_no, amount); break; }}}
Output of above program:Enter account number 1650 Enter amount 200 w for withdraw d for deposit d Previous balance is:2012.0 Current balance is:2212.0 Account type is current therefore threr is no any intrest
Program no:-26
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; class Shape{ Scanner sc=new Scanner(System.in); int x,y,l,b; void getCoord(){ System.out.println("Enter coordinate"); x=sc.nextInt(); y=sc.nextInt(); }
void showCord(){ System.out.println("Given Coodinate value ("+x+","+y+")"); } } class Rect extends Shape{ @Override void getCoord(){ System.out.println("Enter length of rectangle"); l=sc.nextInt(); System.out.println("Enter breadth of rectangle"); b=sc.nextInt(); } @Override void showCord(){ System.out.println("Given length is:"+l+" and breadth is:"+b); } } public class dynamicDispatch26 { public static void main(String args[]){ Shape obj1=new Shape(); Rect obj2=new Rect(); Shape obj; obj=obj1; obj.getCoord(); obj.showCord(); obj=obj2; obj.getCoord(); obj.showCord(); } }
Output of above program:Enter coordinate 3 4 Given Coodinate value (3,4) Enter length of rectangle 34 Enter breadth of rectangle 32 Given length is:34 and breadth is:32
Program no:-31
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /**
* * @author Amit */ public class Matrix31 { public static void main(String args[]){ int matx[][]=new int[4][4]; for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ if(i==j){ matx[i][j]=1; continue; } matx[i][j]=0; } } for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ System.out.print(matx[i][j]); System.out.print(" "); } System.out.println(); }}}
Program no:-33
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; public class ArrayCountOddNEven33 { public static void main(String args[]){ int ar[]=new int[10],oddcount=0,evencount=0; Scanner sc=new Scanner(System.in); System.out.println("Enter any integer :"); for(int i=0;i<10;i++){ ar[i]=sc.nextInt(); } for(int i=0;i<10;i++){ if(ar[i]%2==0)
++evencount; else ++oddcount; } System.out.println("Even number in array list is :"+evencount); System.out.println("Odd number in array list is :"+oddcount);}}
Output of above program:35 43 65 45 77 84 34 64 57 5 Even number in array list is :3 Odd number in array list is :7
Program no:-34
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; public class WeightHeight34 { public static void main(String args[]){ int weight[]=new int[10],height[]=new int[10]; Scanner sc=new Scanner(System.in); System.out.println("Enter weight in kg for 10 persion"); for(int i=0;i<10;i++){ weight[i]=sc.nextInt(); } System.out.println("Enter height in CM for 10 persion"); for(int i=0;i<10;i++){ height[i]=sc.nextInt(); } for(int i=0;i<10;i++){ if((weight[i]<50)&&(height[i]>170)) System.out.println(i+" Persion under weight"); else System.out.println(i+" Persion height weight ration is perfect"); } }}
Output of above program:Enter weight in kg for 10 persion 50 40 30 60 70 87 64 62 73 45 Enter height in CM for 10 persion 124 152 140 170 180 150 126 142 123 128 0 Persion height weight ration is perfect 1 Persion height weight ration is perfect
2 3 4 5 6 7 8 9
is is is is is is is is
Program no:-35
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; public class sortInt35 { public static void main(String args[]){ String name[]=new String[11],temp; Scanner sc=new Scanner(System.in); System.out.println("Enter name of 10 persion"); for(int i=0;i<10;i++){ name[i]=sc.nextLine(); } for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ if(j==9) continue; if((name[j].charAt(0)==name[j+1].charAt(0)) &&(name[j].charAt(1)>name[j+1].charAt(1))) { temp=name[j]; name[j]=name[j+1]; name[j+1]=temp; } if(name[j].charAt(0)>name[j+1].charAt(0)){ temp=name[j]; name[j]=name[j+1]; name[j+1]=temp; } } } System.out.println("Sorted name of 10 persion"); for(int i=0;i<10;i++){
Output of above program:Enter name of 10 persion ravi rohit mohit amit asmita ashotosh ankit om shailja vinay Sorted name of 10 persion amit ankit asmita ashotosh mohit om ravi rohit shailja vinay
Program no:-36
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner; public class AnualExamination36 { public static void main(String args[]){ int sub1[]={33,58,60,67,68,63,57,78,89,94}; int sub2[]={52,39,45,60,74,56,67,62,89,90}; int sub3[]={54,56,78,89,90,98,52,34,33,45}; int Roll[]={11245,11263,12458,42105,12458,31147,41250,11478,13658,18018};
int total_m[]=new int[10]; char ch; Scanner sc=new Scanner(System.in); for(int i=0;i<10;i++){ total_m[i]=sub1[i]+sub2[i]+sub3[i]; } System.out.println("(a) Total marks obtained by each student."); System.out.println("(b) The highest marks in each subject and the Roll No. of the student who secured it."); System.out.println("(c) The student who obtained the highest total marks."); ch=sc.findInLine(".").charAt(0); switch(ch){ case 'a': break; case 'b': break; case 'c': break; } for(int i=0;i<10;i++){ if((sub1[i]>sub2[i])&&(sub1[i]>sub3[i])) System.out.println(Roll[i]+" is a roll no. got max marks in 1st subject "+sub1[i]); if((sub2[i]>sub1[i])&&(sub2[i]>sub3[i])) System.out.println(Roll[i]+" is a roll no. got max marks in 2nd subject "+sub2[i]); if((sub3[i]>sub1[i])&&(sub3[i]>sub2[i])) System.out.println(Roll[i]+" is a roll no. got max marks in 3rd subject "+sub3[i]); } } }
Output of above program:(a) Total marks obtained by each student. (b) The highest marks in each subject and the Roll No. of the student who secured it. (c) The student who obtained the highest total marks. b 11245 is a roll no. got max marks in 3rd subject 54 11263 is a roll no. got max marks in 1st subject 58 12458 is a roll no. got max marks in 3rd subject 78 42105 is a roll no. got max marks in 3rd subject 89 12458 is a roll no. got max marks in 3rd subject 90 31147 is a roll no. got max marks in 3rd subject 98 41250 is a roll no. got max marks in 2nd subject 67 11478 is a roll no. got max marks in 1st subject 78 18018 is a roll no. got max marks in 1st subject 94
Program no:-37
/* * To change this template, choose Tools | Templates
* and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class mergeArray37 { public static void main(String args[]){ int ary1[]={4,6,7,8,9,23,26,28,29,30}; int ary2[]={3,8,24,29,32,33,37}; int len1,len2,len,index1=0,index2=0,index=0; len1=ary1.length; len2=ary2.length; len=len1+len2; int ary[]=new int[len]; for(int i=0;i<len;i++){ if((index1==10)||(index2==7)) continue; if(ary1[index1]<ary2[index2]) ary[index++]=ary1[index1++]; else ary[index++]=ary2[index2++]; } if(index1!=len1){ for(int j=len-(len1-index1);j<len;j++) ary[j]=ary1[index1++]; } else{ for(int j=len-(len2-index2);j<len;j++) ary[j]=ary2[index2++]; } for(int i=0;i<len;i++){ System.out.print(ary[i]); System.out.print(" "); } } }
* and open the template in the editor. */ package labexercise; /** * * @author Amit */ public class StringBuffer38 { public static void main(String args[]){ StringBuffer sb=new StringBuffer("My name is Rohit"); System.out.println("Length of String is :"+sb.length()); System.out.println("Capacity of String is :"+sb.capacity());//16+length of string System.out.println("Character of String written if 1st position is :"+sb.charAt(0)); sb.replace(1,2,"I"); System.out.println("Replace 2nd character with I :"+sb); sb.setLength(2); System.out.println("Set the length of string as 2 character :"+sb); sb.insert(0,"Mission imposible"); System.out.println("After inserting the string :"+sb); sb.reverse(); System.out.println("After revesing the string :"+sb); } }
Output of above program:Length of String is :16 Capacity of String is :32 Character of String written if 1st position is :M Replace 2nd character with I :MI name is Rohit Set the length of string as 2 character :MI After inserting the string :Mission imposibleMI After revesing the string :IMelbisopmi noissiM
Program no:-39
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package labexercise; /** * * @author Amit */ import java.util.Scanner;
public class concatenates39 { public static void main(String args[]) throws NullPointerException { char sel; String str1="Event Handlers is dedicated",str; String str2="to make your event"; String str3="a most memorable one Madam."; Scanner sc= new Scanner(System.in); System.out.println("(a)--For Identify the length of a String"); System.out.println("(b)--For Identify the index of the character e after leaving 3 characters"); System.out.println("(c)--For Replace all small a character with capital A"); System.out.println("(d)--For Verify that the String is ending with Madam"); System.out.println("(e)--For Extract the String Madam and Verify that it is a palindrome."); System.out.println("(f)--For Count the total number of Vowels with the frequency in the given String."); sel=sc.findInLine(".").charAt(0); str=str1+" "+str2+" "+str3; char cha[]=new char[str.length()]; //System.out.println(str); switch(sel) { case 'a': { System.out.println("Length of the string"); System.out.println(str.length()); } break; case 'b': { for(int i=0;i<=str.length();i=i+3){ if(str.charAt(i)=='e') System.out.print("Index are :"+i); } } break; case 'c' : { System.out.println("Modify string is:-"); for(int i=0;i<str.length();i++){ if(str.charAt(i)=='a'){ cha[i]='A'; System.out.print(cha[i]); continue; } cha[i]=str.charAt(i); System.out.print(cha[i]); }
} break; case 'd': { System.out.print("It Verify that the String is ending with Madam"); } break; case 'e': { String st="madam"; boolean flag=false; int len=st.length(),len2; len2=len; for(int i=0;i<len;i++){ if(st.charAt(len2-1)==st.charAt(i)){ --len2; flag=true; } else { flag=false; break; } } if(flag) System.out.print("It Verify that the string Madam is palindrom"); else System.out.print("string Madam is not palindrom"); } break; case 'f': { int len,z=1,count=1; len=str.length(); char ch[]=new char[len+2],ch2[]=new char[len]; int lenOfChar[]=new int[len]; for(int i=0;i<len;i++){ ch[i]=str.charAt(i); } for(int j=0;j<len;j++){ for(int i=z;i<len;i++){ if(ch[i]==0) continue; if(ch[j]==ch[i]){ ++count; ch[i]=0; } } ++z; ch2[j]=ch[j];
lenOfChar[j]=count; count=1; } for(int i=0;i<len;i++){ if(ch[i]==0) continue; System.out.println("Number of character "+ch2[i]+" comes "+lenOfChar[i]);}}}}}
Output of above program:(a)--For Identify the length of a String (b)--For Identify the index of the character e after leaving 3 characters (c)--For Replace all small a character with capital A (d)--For Verify that the String is ending with Madam (e)--For Extract the String Madam and Verify that it is a palindrome. (f)--For Count the total number of Vowels with the frequency in the given String. f Number of character E comes 1 Number of character v comes 2 Number of character e comes 10 Number of character n comes 4 Number of character t comes 5 Number of character comes 12 Number of character H comes 1 Number of character a comes 7 Number of character d comes 5 Number of character l comes 2 Number of character r comes 3 Number of character s comes 3 Number of character i comes 2 Number of character c comes 1 Number of character o comes 5 Number of character m comes 5 Number of character k comes 1 Number of character y comes 1 Number of character u comes 1 Number of character b comes 1 Number of character M comes 1 Number of character . comes 1