ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

Embed Size (px)

Citation preview

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    1/106

    Class SMITH 1/2

    import java.io.*;public class SMITH{ int n; void input()throws IOException { DataInputStream d=new DataInputStream(System.in); System.out.println("ENTER A NUMBER"); n=Integer.parseInt(d.readLine()); } int sumDigits() { int m=n,d=0,s=0;

    while(m>0) { d=m%10; s+=d; m/=10; } return s; } boolean prime(int m) { int d=m/2,c=0; for(int i=2;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    2/106

    Class SMITH (continued) 2/2

    s+=d; j/=10; } m=m/i; break; } } } return s; }

    void main()throws IOException {

    SMITH s=new SMITH(); s.input(); if(s.sumDigits()==s.sumPrime()) System.out.println("SMITH NUMBER"); else System.out.println("not a SMITH NUMBER"); }}

    Jan 20, 2015 1:55:00 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    3/106

    ENTER A NUMBER666SMITH NUMBER

    ENTER A NUMBER908not a SMITH NUMBER

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    4/106

    Class fibonacci 1/1

    //fibonacci seriesimport java.io.*;class fibonacci{ int a,b,c,limit; fibonacci() { a=0; b=1; c=1; } void input()throws IOException {

    DataInputStream d=new DataInputStream(System.in); System.out.println("Enter limit of sequence"); limit=Integer.parseInt(d.readLine()); } //method to find nth fibonacci number using recursive technique int fib(int n) { if(n==1) return a; if(n==2) return b; return (fib(n-1)+fib(n-2)); }

    void generateFibSeries() { for(int i=1;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    5/106

    Enter limit of sequence50,1,1,2,3,

    Enter limit of sequence100,1,1,2,3,5,8,13,21,34,Enter limit of sequence110,1,1,2,3,5,8,13,21,34,55,Enter limit of sequence70,1,1,2,3,5,8,

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    6/106

    Class factorial 1/1

    //to find factorial using recursionimport java.io.*;class factorial{ int n,f; factorial() { n=0; f=0; } //finding factorial of n using recursive technique int fact(int num) {

    if(num==0) return 1; return (num*fact(num-1)); } void getnumber(int x) { n=x; f=fact(n); System.out.println("factorial of "+x+"="+f); } void main()throws IOException { factorial fac=new factorial();//object creation

    DataInputStream d=new DataInputStream(System.in); System.out.println("Enter a number"); n=Integer.parseInt(d.readLine()); fac.getnumber(n); }}

    Nov 27, 2014 7:43:38 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    7/106

    Enter a number5factorial of 5=120

    Enter a number10factorial of 10=3628800Enter a number11factorial of 11=39916800Enter a number2factorial of 2=2Enter a number1factorial of 1=1Enter a number0factorial of 0=1

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    8/106

    Class poweris 1/1

    //to find n raised to m using recursive techniqueimport java.io.*;class poweris{ int n,m; double p; poweris() { n=0; m=0; p=0.0; } double power(int n,int m)

    { if(m0) return (n*power(n,m-1)); return 1.0; } void findresult()throws IOException { DataInputStream d=new DataInputStream(System.in);

    System.out.println("Enter base and exponent"); n=Integer.parseInt(d.readLine()); m=Integer.parseInt(d.readLine()); p=power(n,m); } void printresult() { System.out.println(n+" to the power "+m+" equals "+p); } void main()throws IOException { poweris po=new poweris(); po.findresult(); po.printresult(); }}

    Nov 27, 2014 7:45:54 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    9/106

    Enter base and exponent23

    2 to the power 3 equals 8.0Enter base and exponent131 to the power 3 equals 1.0Enter base and exponent2-22 to the power -2 equals 0.25Enter base and exponent8-28 to the power -2 equals 0.015625

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    10/106

    Class Revstr 1/1

    //to reverse string using recursionimport java.io.*;class Revstr{ String Str,Revst; void getStr()throws IOException { DataInputStream d=new DataInputStream(System.in); System.out.println("Enter a string"); Str=d.readLine(); } void recReverse(int i) {

    if(i>0) { Revst+=Str.charAt(i); recReverse(i-1); } if(i==0) Revst+=Str.charAt(0); } void check() { Revst=""; System.out.println("original "+Str); recReverse(Str.length()-1);

    System.out.println("reversed "+Revst); int i=0; for(i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    11/106

    Enter a stringthis is a jolly good placeoriginal this is a jolly good place

    reversed ecalp doog ylloj a si sihtNot PalindromeEnter a stringcomputer retupmocoriginal computer retupmocreversed computer retupmocPalindromeEnter a string78987original 78987reversed 78987Palindrome

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    12/106

    Class theseries 1/2

    //to find primes from a list of data using recursion

    import java.io.*;class theseries{ int limit; int arr[]=new int[150];

    theseries() { limit=0; for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    13/106

    Class theseries (continued) 2/2

    { theseries ts=new theseries(); ts.readList(); ts.printPrimes(); }}

    Jan 19, 2015 7:06:07 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    14/106

    enter limit of array5enter elements of array

    enter element 111enter element 2111enter element 371enter element 429enter element 52list of primes from the array11 71 29 2enter limit of array3enter elements of arrayenter element 16enter element 212enter element 314list of primes from the array

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    15/106

    Class check 1/1

    //to count number of words in a string starting with a capital letterimport java.io.*;class check{ String Str; int w; void inputString()throws IOException { Str=" "; DataInputStream d=new DataInputStream(System.in); System.out.println("Enter a sentence"); Str+=d.readLine(); }

    void counter(int p) { if((p+1)=65&&Str.charAt(p+1)

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    16/106

    Enter a sentenceThis Is a joLly Good daY.String entered This Is a joLly Good daY.

    Number of words starting with capital letter3Enter a sentencethis Computer Project iS Created by Prasoon.String entered this Computer Project iS Created by Prasoon.Number of words starting with capital letter4Enter a sentencekilling animals for fun has been bannedString entered killing animals for fun has been bannedNumber of words starting with capital letter0

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    17/106

    Class binary 1/1

    //to convert binary(base 2) to decimal(base 10)import java.io.*;class binary{ long bin; long dec; void readBinary()throws IOException { DataInputStream d=new DataInputStream(System.in); System.out.println("Enter a binary number"); bin=Long.parseLong(d.readLine()); } long convertDec(long c)

    { if(bin==0) return 0; long d=bin%10; bin=bin/10; dec=convertDec(c+1)+d*(long)Math.pow(2,c); return dec; } void show() { System.out.println("binary number entered "+bin); System.out.println("Equivalent decimal form "+convertDec(0)); }

    void main()throws IOException { binary b=new binary(); b.readBinary(); b.show(); }}

    Nov 27, 2014 7:48:50 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    18/106

    Enter a binary number100binary number entered 100

    Equivalent decimal form 4Enter a binary number10101binary number entered 10101Equivalent decimal form 21Enter a binary number11111binary number entered 11111Equivalent decimal form 31Enter a binary number110110binary number entered 110110Equivalent decimal form 54

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    19/106

    Class sum_series 1/1

    //to find sum of series (x*x)/1+(x*x*x*x)/(2*2)+(x*x...6times)/(3*3*3)...n termsimport java.io.*;class sum_series{ int x; int n; double sum; DataInputStream d=new DataInputStream(System.in); sum_series() { x=0; n=0;

    sum=0.0; } void readLimit()throws IOException { System.out.println("Enter limit of series"); n=Integer.parseInt(d.readLine()); } int getPower(int m,int p) { if(p>0) return (m*getPower(m,p-1)); return 1; }

    void Sum() { for(int i=1;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    20/106

    Enter variable x2Enter limit of series

    5Sum of Series 11.698050370370371Enter variable x3Enter limit of series6Sum of Series 112.16521125Enter variable x1Enter limit of series5Sum of Series 1.291263287037037Enter variable x0Enter limit of series20Sum of Series NaNEnter variable x2Enter limit of series12Sum of Series 11.746671032880755

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    21/106

    Class words 1/2

    //to find number of words in a stringimport java.io.*;class words{ String text; int w; words() { text=null; w=0; } void Accept()throws IOException {

    DataInputStream d=new DataInputStream(System.in); System.out.println("Enter a sentence"); text=d.readLine(); } int FindWords(int c) { if(c>0) { if(text.charAt(c)==32) { if(text.charAt(c-1)==32) { w=FindWords(c-1);

    return w; } else { w=FindWords(c-1)+1; return w; } } w=FindWords(c-1); return w; } w=1; return w; } void Result() { System.out.println("Sentence entered"+text); System.out.println("Number of words in the sentence "+FindWords(text.length()-1)); } void main()throws IOException { words wrds=new words();

    Nov 27, 2014 7:49:43 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    22/106

    Class words (continued) 2/2

    wrds.Accept(); text=" "+text; wrds.Result(); }}

    Nov 27, 2014 7:49:43 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    23/106

    Enter a sentencea terrible time awaited the country.Sentence entereda terrible time awaited the country.

    Number of words in the sentence 6Enter a sentenceattack on sierra leone is at 1600 hrs. sharpSentence enteredattack on sierra leone is at 1600 hrs. sharpNumber of words in the sentence 9Enter a sentenceThis output is generated by BlueJ 3.0.0Sentence enteredThis output is generated by BlueJ 3.0.0Number of words in the sentence 7

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    24/106

    Class matrix_image 1/2

    import java.io.*;class matrix_image{ double arr1[][]=new double[15][15]; double arr2[][]=new double[15][15]; int m,n;//integers to store number of rows and columns matrix_image() { for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    25/106

    Class matrix_image (continued) 2/2

    System.out.println("MATRIX INPUTED"); for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    26/106

    Enter number of rows2Enter number of columns

    3ENTER ELEMENT ON ADDRESS 0,02ENTER ELEMENT ON ADDRESS 0,13ENTER ELEMENT ON ADDRESS 0,24ENTER ELEMENT ON ADDRESS 1,06ENTER ELEMENT ON ADDRESS 1,110ENTER ELEMENT ON ADDRESS 1,212MATRIX INPUTED2.0 3.0 4.06.0 10.0 12.0MIRROR IMAGE OF THE MATRIX INPUTED4.0 3.0 2.012.0 10.0 6.0Enter number of rows3Enter number of columns2ENTER ELEMENT ON ADDRESS 0,03

    ENTER ELEMENT ON ADDRESS 0,15ENTER ELEMENT ON ADDRESS 1,07ENTER ELEMENT ON ADDRESS 1,111ENTER ELEMENT ON ADDRESS 2,013ENTER ELEMENT ON ADDRESS 2,117MATRIX INPUTED3.0 5.07.0 11.0

    13.0 17.0MIRROR IMAGE OF THE MATRIX INPUTED5.0 3.011.0 7.017.0 13.0

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    27/106

    Class series 1/1

    import java.io.*;class series{ int n; int a,b,c; void inputlimit()throws IOException { DataInputStream d=new DataInputStream(System.in); System.out.println("Input Total number of terms"); n=Integer.parseInt(d.readLine()); } void assign() {

    a=0; b=1; } void generateseries()throws IOException { inputlimit(); assign(); if(n==1) System.out.println(a); if(n==2) System.out.println(a+" "+b); if(n>2) {

    System.out.print(a+" "+b+" "); for(int i=3;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    28/106

    Class maxmin 1/1

    import java.io.*;class maxmin extends series{ int ar[]=new int[100]; int s; int gn,sn; void readarray()throws IOException { DataInputStream d=new DataInputStream(System.in); System.out.println("Enter size of array"); s=Integer.parseInt(d.readLine()); System.out.println("Enter the array"); for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    29/106

    Class definingMain 1/1

    import java.io.*;class definingMain{ void main()throws IOException { maxmin mm=new maxmin(); mm.printresults(); }}

    Jan 17, 2015 11:46:19 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    30/106

    Input Total number of terms100 1 1 2 3 5 8 13 21 34

    Enter size of array5Enter the arrayEnter the array element 111Enter the array element 213Enter the array element 319Enter the array element 42Enter the array element 53Greatest number in array19Smallest number in array2

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    31/106

    Class IscScores 1/1

    import java.io.*;class IscScores{ int number[][]=new int[6][2]; IscScores() { for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    32/106

    Class BestFour 1/1

    import java.io.*;class BestFour extends IscScores{ void bestsubjects()throws IOException { IscScores isc=new IscScores(); isc.inputMarks(); int s=0; for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    33/106

    Class defineMain 1/1

    import java.io.*;class defineMain{ void main()throws IOException { BestFour bf=new BestFour(); bf.bestsubjects(); }}

    Jan 17, 2015 11:48:35 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    34/106

    Enter Subject Code983Enter Marks

    100Enter Subject Code981Enter Marks95Enter Subject Code589Enter Marks100Enter Subject Code232Enter Marks100Enter Subject Code897Enter Marks86Enter Subject Code789Enter Marks96TOTAL POINTS7789232983

    589

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    35/106

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    36/106

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    37/106

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    38/106

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    39/106

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    40/106

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    41/106

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    42/106

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    43/106

    Class Student 1/1

    packageInheritance.sample2;

    importjava.io.*;

    public classStudent{ String std; introll;

    DataInputStream d=newDataInputStream(System.in);

    voidaccept() throwsIOException { System.out.println("ENTER NAME"); std=d.readLine(); System.out.println("ENTER ROLL NUMBER"); roll=Integer.parseInt(d.readLine()); }

    voidshow()throwsIOException { System.out.println("NAME "+std); System.out.println("ROLL NUMBER "+roll); } }

    Jan 17, 2015 9:43:47 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    44/106

    Class Marks 1/1

    packageInheritance.sample2;

    importjava.io.*;

    public classMarks extendsStudent{ protected floatsub1; protected floatsub2;

    DataInputStream d=newDataInputStream(System.in);

    voidgetMarks(floatx,floaty)throwsIOException { sub1=x; sub2=y; }

    voiddispMarks()throwsIOException { System.out.println("SUB1 "+this.sub1); System.out.println("SUB2 "+this.sub2); }}

    Jan 17, 2015 9:44:12 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    45/106

    Class Result 1/1

    packageInheritance.sample2;

    importjava.io.*;

    public classResult extendsMarks{ floattotal;

    DataInputStream d=newDataInputStream(System.in);

    voidDisplay()throwsIOException { total=sub1+sub2; show(); dispMarks(); System.out.println("TOTAL "+total); }}

    Jan 17, 2015 9:44:24 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    46/106

    Class run 1/1

    packageInheritance.sample2;

    importjava.io.*;

    public classrun{ DataInputStream d=newDataInputStream(System.in); voidmain()throwsIOException { Result obj1=newResult(); obj1.accept(); floatx,y; System.out.println("ENTER MARKS IN SUB1 "); x=Float.parseFloat(d.readLine()); System.out.println("ENTER MARKS IN SUB2"); y=Float.parseFloat(d.readLine()); obj1.getMarks(x,y); obj1.Display(); }}

    Jan 17, 2015 9:44:32 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    47/106

    run2.main();ENTER NAME

    AMRENDRAENTER ROLL NUMBER

    013ENTER MARKS IN SUB1

    99ENTER MARKS IN SUB2

    100NAME AMRENDRA

    ROLL NUMBER 13

    SUB1 99.0

    SUB2 100.0

    TOTAL 199.0

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    48/106

    Class basePro 1/1

    packageInheritance.sample1;importjava.io.*;

    public classbasePro{ floatn1; floatn2;

    DataInputStream d=newDataInputStream(System.in);

    voidenter()throwsIOException { System.out.println("ENTER NUMBER"); n1=Float.parseFloat(d.readLine()); System.out.println("ENTER NUMBER"); n2=Float.parseFloat(d.readLine()); }

    voidshow() { System.out.println("NUMBER 1="+n1); System.out.println("NUMBER 2="+n2); } }

    Jan 17, 2015 9:40:19 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    49/106

    Class dervPro 1/1

    packageInheritance.sample1;

    importjava.io.*;

    public classdervPro extendsbasePro{ floatresult;

    DataInputStream d=newDataInputStream(System.in);

    voidprod()throwsIOException { enter(); result=n1*n2; }

    voiddisp() { System.out.println("MULTIPLICATION RESULT="+result); }

    }

    Jan 17, 2015 9:40:40 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    50/106

    Class run 1/1

    packageInheritance.sample1;

    importjava.io.*;

    public classrun{ DataInputStream d=newDataInputStream(System.in);

    public voidmain() throwsIOException { dervPro obj1=newdervPro(); obj1.prod(); obj1.disp(); } }

    Jan 17, 2015 9:41:01 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    51/106

    run1.main();ENTER NUMBER

    6ENTER NUMBER

    3MULTIPLICATION RESULT=18.0

    run1.main();ENTER NUMBER

    12ENTER NUMBER

    8MULTIPLICATION RESULT=96.0

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    52/106

    Class Alpha 1/3

    /*** QUESTION*

    * design a class Alpha which enables the characters of a string to* be arranged in alphabetical order.* the details of the members of the class are given below:** Data members:* Str :to store the original sentence* Rstr :to store the arranged letters** Member functions:* Alpha() :dafault constructor* void readString() :to accept a sentence in uppercase* void remove_spaces :removes all the white spaces in the string* void arrange :to arrange the letters of the sentence in* alphabetical order using bubble sort* technique* void disp() :displays the original sentence* and the arranged string.*/

    importjava.io.*;public classAlpha{ String Str; //CREATING DATA MEMBERS String Rstr; //CREATING DAT MEMBERS

    DataInputStream d=newDataInputStream(System.in);

    publicAlpha() //DEFAULT CONSTUCTOR { Str=""; //initialising data members Rstr=""; }

    voidreadString() throwsIOException /* * method to input a string in upper case

    */ { System.out.println("ENTER A SENTENCE IN UPPERCASE"); Str=d.readLine(); }

    voidremove_spaces() /* * method to remove spaces from the string */ { intl=Str.length(); String s="";

    Jan 16, 2015 10:37:52 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    53/106

    Class Alpha (continued) 2/3

    for(inti=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    54/106

    Class Alpha (continued) 3/3

    } Rstr=a; /*

    * giving the data member Rstr the value of the arranged string a */ } voiddisp() { System.out.println("Original sentence\t"+ Str); /* * displaying original string */ System.out.println("arranged string\t"+ Rstr); /* * displaying arranged string */ } public voidmain() throwsIOException { Alpha o1=newAlpha(); /* * creating object using default * constructor */ o1.readString(); o1.remove_spaces(); o1.arrange(); o1.disp();

    /* * calling member functions using object */ } //end of main} //end of class

    Jan 16, 2015 10:37:52 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    55/106

    alpha1.main();ENTER A SENTENCE IN UPPERCASE

    SUN RISES FROM THE EASTOriginal sentence SUN RISES FROM THE EAST

    arranged string AEEEFHIMNORRSSSSTTU

    alpha1.main();ENTER A SENTENCE IN UPPERCASE

    AMIR KHAN IS A VERY GOOD ACTOROriginal sentence AMIR KHAN IS A VERY GOOD ACTOR

    arranged string AAAACDEGHIIKMNOOORRRSTVY

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    56/106

    Class armstrong_number 1/1

    /*** QUESTION*

    * Design a program in java to check whether a number* is an armstrong number or not.* An armstrong number is a number in which the sum* ofcubes of every digit of the number is equal to* the number itself.* eg. 153 = 1^3 + 5^3 +3^ 3 = 1+125+27 = 153*/

    importjava.io.*;public classarmstrong_number{ public voidmain()throwsIOException { DataInputStream d=newDataInputStream(System.in); System.out.println("enter the number"); int n=Integer.parseInt(d.readLine()); intm=n; //creating dummy variable ints=0; intr=0; while(m>0) { r=m%10; s=s+(r*r*r); //finding sum of cubes of digits of the number m=m/10; }

    if(n==s) /** checking if sum of cubes of every digit if the number * is equal to the number itself and then displaying messages * accordingly. */ { System.out.println("Number is an armstrong number"); } else { System.out.println("Number is not an armstrong number"); } }

    }

    Jan 16, 2015 11:02:54 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    57/106

    armstron1.main();enter the number

    153Number is an armstrong number

    armstron1.main();enter the number

    523Number is not an armstrong number

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    58/106

    Class Change 1/2

    packageRecursion;

    /*** QUESTION* PROGRAM TO CONVERT THE CASE OF A STRING**/

    importjava.io.*;

    public classChange{ String str; //data members

    String newstr; //data members intlen; //data members

    DataInputStream d=newDataInputStream(System.in);

    Change() //default constructor { str=""; newstr=""; len=0; }

    //method to input the word

    voidinputword()throwsIOException { System.out.println("ENTER A WORD"); str=d.readLine(); }

    //function to convert case of a character charcaseconvert(charch) { intk=0; if(ch!=' ') { if(ch>92) {

    k=ch-32;//case conversion to capital } else { k=ch+32;//case conversion to small } } else

    Jan 1, 2003 1:13:37 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    59/106

    Class Change (continued) 2/2

    { k=ch; } return(char)k; //returning character of opp. case }

    //recursive function voidrecchange(intn) { if(n

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    60/106

    change1.main();ENTER A WORD

    CITy MONTESSori scHOOLORIGINAL WORD CITy MONTESSori scHOOL

    CHANGED WORD citY montessORI SChool

    change1.main();ENTER A WORD

    The HOunD OF basKERvilleSORIGINAL WORD The HOunD OF basKERvilleS

    CHANGED WORD tHE hoUNd of BASkerVILLEs

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    61/106

    Class Check 1/1

    packageRecursion;

    importjava.io.*;

    public classCheck{ String Str; intw;

    DataInputStream d=newDataInputStream(System.in);

    voidInputString() throwsIOException {

    System.out.println("ENTER STRING"); Str=" "+(d.readLine()).trim()+" 0"; }

    voidCounter(intn) { if(n>-1) { if(Str.charAt(n)==' ') { if(Str.charAt(n+1)=='A'||Str.charAt(n+1)=='E'||Str.charAt(n+1) =='I'||Str.charAt(n+1)=='O'||Str.charAt(n+1)=='U')

    { w++; } } Counter(n-1); } }

    voidDisp() { Counter((Str.length()-1)); System.out.println("NO OF WORDS BEGINING WITH CAPITAL VOWELS ARE "+w); }

    voidmain() throwsIOException { Check ob1=newCheck(); ob1.InputString(); ob1.Disp(); }}

    Jan 1, 2003 1:02:30 AM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    62/106

    check1.main();ENTER STRING

    ANDREW IS a good boyNO OF WORDS BEGINING WITH CAPITAL VOWELS ARE 2

    check1.main();ENTER STRING

    I am Out of work since last MonthNO OF WORDS BEGINING WITH CAPITAL VOWELS ARE 2

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    63/106

    Class climbing_number 1/2

    /**** QUESTION

    ** Design a program in java to check whether a number* is climbing number or not.Also print the digits of* the number.* A climbing number is a number whose digits are in* ascending order.* eg. 123 ,159 ,126 ,etc.*/

    importjava.io.*;public classclimbing_number{public voidmain()throwsIOException { DataInputStream d=newDataInputStream(System.in); System.out.println("enter the number"); int n=Integer.parseInt(d.readLine()); intc=0; //counter to store number of digits of the number inta=n; intz=n; while(a>0)//loop to count no of digits { c=c+1; //updating counter variable to count no. of digits

    a=a/10; } intm[]=new int[c]; inty=0; for(inti=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    64/106

    Class climbing_number (continued) 2/2

    * we compare every digit eith the next digit. * If every digit is smaller than the next digit * then the number must be climbing.

    * So we count the number of times the required condition * is true for the number .If it is 1 less than the total * number of digits then the number must be clmbing because * we have to compare the digits c-1 times . * So if every time it is true then our condition is fullfiled. */ } if(p==(c-1))//checking if digits are in increasing order { System.out.println("climbing number"); } else { System.out.println("not a climbing number"); } }//end of main method}//end of class

    Jan 16, 2015 10:22:36 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    65/106

    climbing1.main();enter the number

    1231 2 3 climbing number

    climbing1.main();enter the number

    5645 6 4 not a climbing number

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    66/106

    Class climbing_prime 1/2

    /*** QUESTION

    ** Design a program in java to check whether a number is a* climbing prime or not.* A climbing prime is a number which is prime and also a* climbing number(whose digits are in ascending order)* eg, 137*/

    importjava.io.*;public classclimbing_prime{ booleanprime(intn) { intv=0; for(intg=1;g0)

    //loop to count no of digits { c=c+1; //updating counter variable to count no. of digits a=a/10; } intm[]=new int[c]; inty=0; for(inti=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    67/106

    Class climbing_prime (continued) 2/2

    //storing digits of the number in an array z=z/10; //updating loop variable

    } intp=0; for(inte=0;em[e+1]) //comparing digits of the number { p=p+1; //counting the no. of times where a digit is smaller than //the next digit.(array is storing the digits fom last to first) } } if(p==(c-1)) //checking if digits are in increasing order { return true; } else { return false; } }

    public voidmain()throwsIOException

    { DataInputStream d=newDataInputStream(System.in); System.out.println("enter the number"); int n=Integer.parseInt(d.readLine()); climbing_prime obj1=newclimbing_prime(); /** If the number is climbing and prime both simultaneously * then only is the number a climbing prime.*/ if(climbing(n)) { if(prime(n)) { System.out.println("its a climbing prime");

    } else { System.out.println("its not a climbing prime"); } } else { System.out.println("its not a climbing prime"); } }//end of main}//end of class

    Jan 16, 2015 10:33:48 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    68/106

    climbing1.main();enter the number

    137its a climbing prime

    climbing1.main();enter the number

    123its not a climbing prime

    climbing1.main();enter the number

    31its not a climbing prime

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    69/106

    Class factorial 1/1

    importjava.io.*;public classfactorial{

    intn; intf;

    DataInputStream d=newDataInputStream(System.in);

    publicfactorial() { n=0; f=0; }

    intfact(intnum)//recursive method { if(num==0)//base case { return1; } return(num*fact(num-1));//recursive case }

    voidgetnum(intx) { n=x; f=fact(n); System.out.println("FACTORIAL "+f);

    }

    voidmain()throwsIOException { System.out.println("ENTER NUMBER"); int a=Integer.parseInt(d.readLine()); getnum(a); }//end of main}//end of class

    Jan 16, 2015 11:18:27 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    70/106

    factoria1.main();ENTER NUMBER

    5FACTORIAL 120

    factoria1.main();ENTER NUMBER

    6FACTORIAL 720

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    71/106

    Class good_number 1/1

    /**** QUESTION

    ** Design a program in java to check whether a number is* a good number or not.* A good number is a number in which the sum of reciprocals* of every digit equals 1.* eg,* 22 -- 1/2 +1/2 =1* 333 -- 1/3 +1/3 +1/3 =1*/importjava.io.*;public classgood_number{ public voidmain()throwsIOException { DataInputStream d=newDataInputStream(System.in); System.out.println("enter the number"); int a=Integer.parseInt(d.readLine()); doublec=0; //variable to store sum of reciprocals of digits intm=a; //creating dummy variable doubler=0; while(m>0) { r=m%10;

    c=c+(1/r); /* * finding the sum of reciprocals of the digits of the * inputed number. */ m=m/10; } /* * if the sum is equal to 1 then the number is * good number. */ if(c==1)

    { System.out.println("its a good number"); } else { System.out.println("its not a good number"); } }//end of main}//end of clss

    Jan 16, 2015 10:18:47 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    72/106

    good_num1.main();enter the number

    22its a good number

    good_num1.main();enter the number

    56its not a good number

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    73/106

    Class Change 1/2

    packageRecursion;

    /**

    * PROGRAM TO CHANGE THE CASE OF A STRING**/

    importjava.io.*;

    public classChange{ String str; //data members String newstr; //data members intlen; //data members

    DataInputStream d=newDataInputStream(System.in);

    Change() //default constructor { str=""; newstr=""; len=0; }

    //method to input the word voidinputword()throwsIOException { System.out.println("ENTER A STRING");

    str=d.readLine(); }

    //function to convert case of a character charcaseconvert(charch) { intk=' '; if(ch!=' ') { if(ch>92) {

    k=ch-32;//case conversion to capital } else { k=ch+32;//case conversion to small } } return(char)k; //returning character of opp. case }

    //recursive function voidrecchange(intn) {

    Jan 19, 2015 11:16:52 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    74/106

    Class Change (continued) 2/2

    if(n

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    75/106

    change1.main();ENTER A STRING

    ToDAy iS THursDAyORIGINAL WORD ToDAy iS THursDAy

    CHANGED WORD tOdaY Is thURSdaY

    change1.main();ENTER A STRING

    THe tAj maHal iS in AgRAORIGINAL WORD THe tAj maHal iS in AgRA

    CHANGED WORD thE TaJ MAhAL Is IN aGra

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    76/106

    Class happy 1/2

    /*** A Happy number is a number for which sum of squares of* digits finally comes out o be 1.

    * For Example: 139* 1. 139 : 1 + 9 +81 = 91* 2. 91 : 81 + 1 = 82* 3. 82 : 64 + 4 = 68* 4. 68 : 36 + 64 = 100* 5. 100 : 1 + 0 +0 = 1** Number of steps =5** CLASS NAME : happy* DATA MEMBERS : n TO STORE THE NUMBER* FUNCIONS :* happy() : constructor to assign 0 to n* void getnum(int nn) : to assign parameter value to n* int power(int nn) :to return square of a number* int sumOfSquares(int nn) :returns sum of square of digits of a number* void ishappy() :to check if the given number is happy or not** Also find the number of steps required in the process for each number.* Also define the main() function to exeute the program by creating object.*/

    importjava.io.*;public classhappy{

    intn; publichappy() //default constuctor { n=0;//initialing data member }

    DataInputStream d=newDataInputStream(System.in);

    public voidgetnum(intnn)//method to assign inputed value to n { n=nn; }

    public intpower(intnn)//to find and return square of a number { intp=nn*nn; returnp; }

    public intsumOfSquares(intnn)//to calculate sum of square { intm=nn;//creating dummy variable intr=0; intps=0;//to store sum of squares intt=0;

    Jan 16, 2015 11:14:20 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    77/106

    Class happy (continued) 2/2

    System.out.print(nn+"\t="); //to print the process(only for understaning) while(m>0)

    { r=m%10; t=power(r); ps=ps+t;//calculating sum m=m/10;//updating loop variable System.out.print("\t"+t+( m>0 ? "\t+":" ")); //to print the process(only for understaning) } System.out.println(); returnps;//returning sum of squares of the digits }

    public voidishappy() { intmm=n; intc=0;//counter to cont no of steps taken do { mm=sumOfSquares(mm); c++; }while(mm>9); //checking if sum of square is single digit

    if(1==mm)//checking if final sum is equal to 1 {

    System.out.println("It is a happy number"); System.out.println("No of steps = "+c); //printing number of steps System.out.println(); } else { System.out.println("It is not a happy number"); } }

    public voidmain()throwsIOException

    { System.out.println("Enter a number"); int nn=Integer.parseInt(d.readLine());//inputing number System.out.println(); happy ob1=newhappy();//creating object ob1.getnum(nn);//calling function via object ob1 ob1.ishappy();//calling function via object ob1 }//end of main

    }//end of class

    Jan 16, 2015 11:14:20 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    78/106

    happy1.main();Enter a number

    139

    139 = 81 + 9 + 1

    91 = 1 + 81

    82 = 4 + 64

    68 = 64 + 36

    100 = 0 + 0 + 1

    It is a happy number

    No of steps = 5

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    79/106

    Class Numeric 1/2

    /*** QUESTION* A class called Numeric has been defined yo find and display the frequency

    * of each digit present in the number and the product of the digits .* Some of the members of the class are given below :** Data Member : n - long integer type** Member functions :* Numeric(long a) :constructor to assign a to n* void frequency() :to find the frequency of each digit in the number* int product() :to return the product of the digits of the number** Write main() function to implement the above*/

    importjava.io.*;public classNumeric{ longn; publicNumeric(longa)//parameterised constructor { n=a; }

    voidfrequency()//method to find frequency of digits {

    inta[]=new int[10]; //creating an array to store //frequency of digits for(inti=0;i0)

    { r=(int)(m%10); a[r]=(a[r]+1);//finding frequency m=m/10; //updating loop variable } System.out.println("Number entered is "+n); System.out.println("Digit\tfrequency"); for(intj=0;j

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    80/106

    Class Numeric (continued) 2/2

    //printing frequency if it is not 0 } }

    } //end of frequency()

    intproduct() { longm=n; intp=1; longr=0; while(m>0) { r=m%10; p=(int)(p*r); m=m/10; } returnp; }//end of product

    public static voidmain()throwsIOException { DataInputStream d=newDataInputStream(System.in); System.out.println("Enter a number"); long a=Long.parseLong(d.readLine()); Numeric obj1=newNumeric(a); //creating object using //parameterised constructor obj1.frequency();//calling functions

    intp=obj1.product(); System.out.println("Products of digits of the number is "+p); }//end of main()}

    Jan 16, 2015 10:50:33 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    81/106

    Numeric.main();Enter a number

    156Number entered is 156

    Digit frequency

    1 1

    5 1

    6 1

    Products of digits of the number is 30

    Numeric.main();Enter a number

    555Number entered is 555

    Digit frequency

    5 3

    Products of digits of the number is 125

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    82/106

    Class pallindrome 1/1

    /*** QUESTION* Design a program in java to check whether a number

    * is a pallindrome number or not.* A pallindrome number is a number is a number which is* identical to its reverse.* eg, 121,212,etc.*/importjava.io.*;public classpallindrome{ public intreverse(intn) throwsIOException //method to create reverse of a number { intm=n; //creating dummy variable intr=0; ints=0; while(m>0)//loop condition { r=m%10; //last digit extraction s=(s*10)+r; //creating reverse number m=m/10; //updating loop variable } returns;

    //returning reverse of a number } public voidmain() throwsIOException /** method to check if a number is pallindrome*/ { DataInputStream d=newDataInputStream(System.in); System.out.println("enter the number"); //inputing the number int n=Integer.parseInt(d.readLine()); ints= reverse(n); //calling reverse function if(s==n)

    /** comparing reverse of number to original number*/ { System.out.println("Number is pallindrome"); } else { System.out.println("Number is not a pallindrome"); } }//end of main}//end of clss

    Jan 16, 2015 10:56:21 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    83/106

    pallindr1.main();enter the number

    15151Number is pallindrome

    pallindr1.main();enter the number

    122Number is not a pallindrome

    pallindr1.main();enter the number

    22Number is pallindrome

    pallindr1.main();enter the number

    7548Number is not a pallindrome

    pallindr1.main();enter the number

    45654Number is pallindrome

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    84/106

    Class perfect 1/1

    /*** QUESTION*

    * Design a program in java to check whether a number* is a PERFECT number or not.*/

    importjava.io.*;public classperfect{ public intdigit_count(intn)throwsIOException /** method to count no of digts in a number */ { intc=0; intm=n; //creating dummy variable while(m>0) { c=c+1; //counter variable m=m/10; //updating loop variable } returnc; //returning no of digits }//end of digit_count

    public voidmain()throwsIOException { DataInputStream d=newDataInputStream(System.in); System.out.println("enter the number");

    int n=Integer.parseInt(d.readLine()); intc=digit_count(n); //counting digits intp=(int)Math.pow(n,2); //squaring the number inte=(int)Math.pow(10,c); intex=p%e; //extracting c no of digits from end of square of number if(ex==n) { System.out.println("The number is a PERFECT number"); }

    else { System.out.println("The number is not a PERFECT number"); } }}

    Jan 16, 2015 10:59:04 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    85/106

    perfect1.main();enter the number

    25The number is a PERFECT number

    perfect1.main();enter the number

    35The number is not a PERFECT number

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    86/106

    Class poweris 1/1

    /*** PROGRAM TO FIND A NUMBER RAISED TO A GIVEN POWER*/

    importjava.io.*;

    public classpoweris{ intn; intm; doublep; DataInputStream d=newDataInputStream(System.in); poweris() { n=0; m=0; p=0.0; }

    doublepower(intn,intm) { if(m==0||n==1) { return1; } if(m>-1) { return(n*power(n,m-1)); }

    return(power(n,m+1)/n); }

    voidfindresult()throwsIOException { System.out.println("ENTER NUMBER"); n=Integer.parseInt(d.readLine()); System.out.println("ENTER POWER"); m=Integer.parseInt(d.readLine()); p=power(n,m); }

    voidprintresult()throwsIOException { System.out.println(n+" raised to "+m+" is "+p); }

    voidmain()throwsIOException { poweris obj=newpoweris(); obj.findresult(); obj.printresult(); }}

    Jan 16, 2015 11:24:51 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    87/106

    poweris1.main();ENTER NUMBER

    5ENTER POWER

    35 raised to 3 is 125.0

    poweris1.main();ENTER NUMBER

    6ENTER POWER

    26 raised to 2 is 36.0

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    88/106

    Class Prime_Triplets 1/2

    package Practical_Questions.Sample_Questions;/*** QUESION

    ** Program to generate PRIME TRIPLETS between two* given limits.* If no ne are found print appropriate error.*/

    importjava.io.*;

    public classPrime_Triplets{ ints; intl; intc;

    DataInputStream d=newDataInputStream(System.in);

    Prime_Triplets() { c=0; s=0; l=0; }

    booleanis_prime(inta,intn) {

    booleanj=true;

    if(a==1) { j=false; }

    if(n

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    89/106

    Class Prime_Triplets (continued) 2/2

    if(is_prime(x,2)) { if(is_prime(x+2,2))

    { if(is_prime(x+6,2)) { System.out.println(x+"\t"+"\t"+(x+2)+"\t"+(x+6)); c++; return true; } } if(is_prime(x+4,2)) { if(is_prime(x+6,2)) { c++; System.out.println(x+"\t"+"\t"+(x+4)+"\t"+(x+6)); return true; } }

    } return false; }

    voidmain()throwsIOException { Prime_Triplets obj=newPrime_Triplets();

    System.out.println("ENTER LOWER LIMIT"); s=Integer.parseInt(d.readLine()); System.out.println("ENTER UPPER LIMIT"); l=Integer.parseInt(d.readLine());

    System.out.println("PRIME TRIPLETS ARE");

    for(inti=s;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    90/106

    prime_Tr1.main();ENTER LOWER LIMIT

    1ENTER UPPER LIMIT

    20PRIME TRIPLETS ARE

    5 7 11

    7 11 13

    11 13 17

    13 17 19

    17 19 23

    prime_Tr1.main();ENTER LOWER LIMIT

    10ENTER UPPER LIMIT

    30PRIME TRIPLETS ARE

    11 13 17

    13 17 19

    17 19 23

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    91/106

    Class Revstr 1/1

    /*** PROGRAM TO CHECK FOR PALLINDROME STRING*/

    importjava.io.*;public classRevstr{ String Str; String Revst; DataInputStream d=newDataInputStream(System.in); publicRevstr() { Str=""; Revst=""; }

    voidgetStr() throwsIOException { System.out.println("ENTER STRING"); Str=d.readLine(); }

    voidrecReverse(intn) { if(n>-1) { Revst=Revst+Str.charAt(n); recReverse(n-1); }

    } voidcheck() { intl=Str.length(); recReverse(l-1); if(Str.equals(Revst)) //checking equality of strings { System.out.println("PALLINDROME"); //printing appropriate output } else { System.out.println("NOT PALLINDROME");

    //printing appropriate output } } public voidmain() throwsIOException//main() method { Revstr obj =newRevstr(); obj.getStr(); obj.check(); }//end of main}

    Jan 19, 2015 11:09:13 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    92/106

    revstr1.main();ENTER STRING

    AADDAADDAAPALLINDROME

    revstr1.main();ENTER STRING

    ASDFGHJNOT PALLINDROME

    revstr1.main();ENTER STRING

    ASDFGHJKLKJHGFDSAPALLINDROME

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    93/106

    Class Transarray 1/4

    /*** QUESTION*

    * A transpose of an array obtained by interchanging the* elements of the rows and columns.* A class Transarray contains a two dimensional integer* array of order [m*n]. The maximum value possible for* both 'm' and 'n' is 20.** Design a class Transarray to find the transpose of a* given matrix . the details of the members are given* below :** CLASS NAME : Transarray** DATA MEMBERS* arr[][] : stores th matrix elements* m : integer to store the number of rows* n : integer to store the number of columns** MEMBER FUNCTIONS* Transarray() : default constructor* Transarray(int mm,int nn) : to initialise the size of matrix,* m=mm , n=nn* void fillarray() : to enter the elements of the matrix* void transpose(transarray A) : to find the transpose of a given matrix* void disparray() : displays the array in a matrix form*

    * Define main() method to execute the class.*/

    importjava.io.*;public classTransarray{ intarr[][]=new int[20][20]; /* * data member to store the matrix */

    intm; /* * data memebr to store number of rows in the matrix */ intn; /* * data memebr to store number of columns in the matrix */

    DataInputStream d=newDataInputStream(System.in); /* * input stram object. * YOUCAN ALSO USE BUFFERED READER

    Jan 16, 2015 10:45:01 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    94/106

    Class Transarray (continued) 2/4

    */

    /* * default constructor to initialise the array */ publicTransarray() { for(inti=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    95/106

    Class Transarray (continued) 3/4

    for(inti=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    96/106

    Class Transarray (continued) 4/4

    mm=Integer.parseInt(d.readLine()); System.out.println("enter no of columns"); nn=Integer.parseInt(d.readLine());

    /* * inputting the number of rows and number of columns from the user */ /** * if and only when no of rows or and columns both are less than 20, * then only we have to find the transpose. * if any one or both of them exceed 20 we will display the * appropriate message and not find the transpose, as we have * defined the matrix with maximum 20 rows and columns only. */ if(mm

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    97/106

    transarr1.main();enter no of rows

    3enter no of columns

    3enter 0*0 th element

    1enter 0*1 th element

    2enter 0*2 th element

    3enter 1*0 th element

    4enter 1*1 th element

    5enter 1*2 th element

    6enter 2*0 th element

    7enter 2*1 th element

    8enter 2*2 th element

    9original

    1 2 3

    4 5 6

    7 8 9

    transpose

    1 4 7

    2 5 8

    3 6 9

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    98/106

    Class merging 1/2

    import java.io.*;class merging{ int size; int a[]=new int[200]; public void read()throws IOException { DataInputStream d=new DataInputStream(System.in); System.out.println("ENTER SIZE OF ARRAY"); size=Integer.parseInt(d.readLine()); System.out.println("ENTER THE ARRAY"); for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    99/106

    Class merging (continued) 2/2

    { merging x=new merging(); merging y=new merging(); merging z=new merging(); System.out.println("ENTER DETAILS OF THE FIRST ARRAY"); x.read(); System.out.println("ENTER DETAILS OF THE SECOND ARRAY"); y.read(); z=z.merge(x,y); System.out.println("THE FIRST ARRAY"); x.display(); System.out.println("THE SECOND ARRAY"); y.display();

    System.out.println("THE MERGED ARRAY"); z.display(); }}

    Jan 20, 2015 2:00:06 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    100/106

    ENTER DETAILS OF THE FIRST ARRAYENTER SIZE OF ARRAY5

    ENTER THE ARRAY13579ENTER DETAILS OF THE SECOND ARRAYENTER SIZE OF ARRAY6ENTER THE ARRAY2467810THE FIRST ARRAY

    1 3 5 7 9THE SECOND ARRAY

    2 4 6 7 8 10THE MERGED ARRAY

    1 2 3 4 5 6 7 8 9 10

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    101/106

    Class duplicate 1/2

    import java.io.*;class duplicate{ int num[]=new int[10]; void readList()throws IOException { DataInputStream d=new DataInputStream(System.in); System.out.println("ENTER INTEGERS IN ASCENDING ORDER"); for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    102/106

    Class duplicate (continued) 2/2

    { if(a.num[i]==-9999) {a.dispList(i-1); break; } } }

    }

    Jan 20, 2015 2:05:48 PM

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    103/106

    ENTER INTEGERS IN ASCENDING ORDER11

    12233344REQUIRED ARRAY1234ENTER INTEGERS IN ASCENDING ORDER4567777888REQUIRED ARRAY45678

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    104/106

    Class matrix_operation 1/2

    import java.io.*;

    public class matrix_operation

    {

    int ar[][]=new int[10][10];

    int m;

    int n;

    int x;

    DataInputStream d=new DataInputStream(System.in);

    public void getrowcolumn()throws IOException

    {

    System.out.println("enter the number of rows");

    m=Integer.parseInt(d.readLine());

    System.out.println("enter the number of column");

    n=Integer.parseInt(d.readLine());

    }

    public void getmatrix()throws IOException

    {

    for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    105/106

    Class matrix_operation (continued) 2/2

    {

    k=ar[i][j];

    }

    }

    s=s+k;

    }

    System.out.println("Sum of greatest element from each row\t"+s);

    }

    public void change_diagonal()throws IOException

    {

    if(m!=n)

    {

    System.out.println("Its is not a square matrix,so change is not

    possible.");

    }

    else {

    System.out.println("value of x=");

    x=Integer.parseInt(d.readLine());

    for(int i=0;i

  • 7/24/2019 ISC PROJECT COMPUTER APPLICATIONS JAVA PROGRAMS

    106/106

    Sum of greatest element from each row 31

    value of x=

    9

    Resultant Matrix:9 5 7 9

    1 9 9 9

    2 9 9 5

    9 3 2 9

    enter the number of rows

    3

    enter the number of column

    4

    Enter the term of(1,1) element

    3

    Enter the term of(1,2) element

    5

    Enter the term of(1,3) element

    7

    Enter the term of(1,4) element

    4

    Enter the term of(2,1) element

    1

    Enter the term of(2,2) element

    6

    Enter the term of(2,3) element

    4

    Enter the term of(2,4) element

    9

    Enter the term of(3,1) element

    2

    Enter the term of(3,2) element

    4

    Enter the term of(3,3) element

    7

    Enter the term of(3,4) element