ISC COMPUTER PRACTICAL PROJECT FILE

  • Upload
    aakash

  • View
    259

  • Download
    5

Embed Size (px)

Citation preview

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    1/31

    Write a program in Java to accept two positive integers

    m and n, where m is less than n as user input and

    display the number of Composite Magic integers withinm and n along with the frequency.

      AL!"#$%M&Algorithm for void main()&tep '(  START.

    &tep )(  Call function void input() to input 2 numbers.

    &tep *( Call a function void display() and read two numbers m, n.

    &tep +( If mn t!en print "I#$A%I& I#'T* +T -nd.

    &tep ( else run a loop from im to n.

    &tep -( Call boolean isComposite(i) and c!ec true.

    &tep ( Call boolean is/a0ic(i) and c!ec true.

    &tep /( If true t!en print i* f f1.

    &tep 0( -nd loop.

    &tep '1( 'rint t!e fre3uency, f.

    &tep ''( -nd.

    Algorithm for boolean isComposite(n)&tep '(  c4.&tep )(  Run a loop from i to n.

    &tep *( If n5i64 t!en cc1.

    &tep +( -nd loop.

    &tep ( If c2 t!en return true else return false.

    Algorithm for boolean isMagic(n)&tep '(  sumcall function int sum&i0(n).

    &tep )(  Run a loop till sum7.

    &tep *( Repeat Step .

    &tep +( -nd loop.&tep ( If sum6 t!en return true else return false.

    Algorithm for int sumDig(n)&tep '(  s4.

    &tep )(  Run a loop till n864.

    &tep *( ss1n54.

    &tep +( nn94.

    &tep ( -nd loop.

    &tep -( return s.

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    2/31

      2!C3M45$A$#!5

    import :ava.util.Scanner;import :ava.io.  public void input()

      = Scanner sc6new Scanner(System.in);  System.out.println(?-nter m and n?);  m6sc.ne@tInt();  n6sc.ne@tInt();  >  public void display()  = if(mn)  = int f64;  System.out.print(?TB- C/'SIT- /A+IC I#T-+-RS AR-* ?);  for(int i6m;i6n;i11)  = if(isComposite(i)66true is/a0ic(i)66true)  =  System.out.print(i1? ?);  f11; > >

    if(f4)  System.out.println(?DnER-F-#CG E C/'SIT- /A+IC I#T-+-RS IS* ?1f);  else  = System.out.println(?#il?);  System.out.println(?ER-F-#CG E C/'SIT- /A+IC I#T-+-RS IS* ?14); > >  else  System.out.println(?I#$A%I& I#'T?);  >  public boolean isComposite(int n)  = int c64;  for(int i6;i6n;i11)  if(n5i664)  c11;  if(c2)  return true;

      elsereturn false;

      >  public boolean is/a0ic(int n)  = int sum6sum&i0(n);  w!ile(sum7)  sum6sum&i0(sum);  if(sum66)  return true;  else  return false;  >  public int sum&i0(int n)  = int sum64;  w!ile(n864)  = sum6sum1n54;  n6n94; >  return sum;  >  public static void main(Strin0 ar0sH)  = Composite/a0ic ob:6new Composite/a0ic();  ob:.input();  ob:.display();  >>

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    3/31

    6A"#A7L4

    5AM4

    2A$A$894 24&C"#9$#!5

    m int stores t!e lower limit of t!e ran0e.

    n int stores t!e upper limit of t!e ran0e.

    f int stores t!e fre3uency of composite ma0icinte0ers.

    i int loop variable from m to n.

    c int counts t!e number of factors of anumber.

    sum int stores t!e summation of di0its of anumber.

    ob: Composite/a0ic

    an ob:ect to call nonJstatic functions.

    #593$

    -nter m and n44!3$93$

     TB- C/'SIT- /A+IC I#T-+-RS AR-* 4 2K LM NN ML K2 7 44ER-F-#CG E C/'SIT- /A+IC I#T-+-RS IS* K

    #593$

    -nter m and n7!3$93$

     TB- C/'SIT- /A+IC I#T-+-RS AR-* #ilER-F-#CG E C/'SIT- /A+IC I#T-+-RS IS* 4

    #593$

    -nter m and n44!3$93$

    I#$A%I& I#'T

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    4/31

    Write a program in Java to accept two positive integers

    M and 5, where M is between '11 and '1111 and 5 is

    less than '11 as user input. :ind the smallest integer thatis greater than M and whose digits add up to 5 and then

    display it. Also display the total number of digits present

    in the required number.

    AL!"#$%M&

    Algorithm for void main()&tep '(  START.

    &tep )(  Call function void input() to input 2 numbers.

    &tep *( Call a function void compute() and read two numbers /, #.

    &tep +( if ((/644/64444)(#64#44)) t!en +T Step N , else +T StepO.

    &tep ( Run a inPnite loop from i/.

    &tep -( Call lon0 sum(i) and c!ec e3uality wit! #, if true t!en print t!e re3ired number totalno.of di0its.

    &tep ( print "I#$A%I& I#'T.

    &tep /( -nd.

    Algorithm for long sum(n)&tep '(  s4.

    &tep )(  Run a loop till n864.

    &tep *( s s1(n54)

    &tep +( -nd loop.

    &tep ( return s.

    Algorithm for int count(n)&tep '(  c4.

    &tep )(  Run a loop till n864.

    &tep *( cc1.

    &tep +( nn54.

    &tep ( return c.

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    5/31

      2!C3M45$A$#!5

    import :ava.util.Scanner;import :ava.io.  public void input()  = Scanner sc6new Scanner(System.in);  System.out.println(?-nter / and #?);  /6sc.ne@t%on0();  #6sc.ne@t%on0();  >  public void compute()  = if((/644/64444)(#64#44))  for(lon0 i6/;;i11)  = if(sum(i)66#)  = System.out.println(?TB- R-FIR-& #/Q-R * ?1i);  System.out.println(?TTA% #/Q-R E &I+ITS6 ?1count(i));  brea;

      >  >  else

    System.out.println(?I#$A%I& I#'T?);  >  public lon0 sum(lon0 n)  = lon0 s64;  w!ile(n864)  = s6s1(n54);  n6n94;  >  return s;  >  public int count(lon0 n)  = int c64;  w!ile(n864)  = c11;  n6n94;  >  return c;  >  public static void main(Strin0 ar0sH)  = 'ro0ram ob:6new 'ro0ram();  ob:.input();  ob:.compute();  >>

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    6/31

    6A"#A7L4

    5AM4

    2A$A$894 24&C"#9$#!5

    / lon0 stores a number between 44 and 4444 .

    # lon0 stores a number less t!an 44.

    i lon0 loop variable from startin0 from / .

    s lon0 stores t!e summation of di0its of a number.

    c int stores t!e number of di0its of a number.

    ob: 'ro0ram an ob:ect to call nonJstatic functions.

    #593$

    -nter / and #44!3$93$

     TB- R-FIR-& #/Q-R * 7 TTA% #/Q-R E &I+ITS6

    #593$

    -nter / and #N442N!3$93$

     TB- R-FIR-& #/Q-R * M77 TTA% #/Q-R E &I+ITS6 L

    #593$

    -nter / and #77!3$93$

    I#$A%I& I#'T

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    7/31

    Write a program which inputs a positive natural number

    5 and prints all the possible consecutive number

    combinations, which when added give 5.

      AL!"#$%M&

    Algorithm for void main()&tep '(  START.

    &tep )(  Read a number n.

    &tep *( Create a class ob:ect, ob:.

    &tep +( Call a function void display().

    &tep ( -nd.

    Algorithm for void display()&tep '(  sum4, :4, c4.

    &tep )(  If #64 t!en +T Step , else +T Step O .

    &tep *( Start a for loop from i till #. Repeat Steps , L, N, M, O.

    &tep +( sumI, :i1.

    &tep ( Run a w!ile loop till sum# and repeat Step M.

    &tep -( sumsum1:, : :1.

    &tep ( If sum6# t!en print it.

    &tep /( 'rint "I#$A%I& I#'T.

     

    2!C3M45$A$#!5

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    8/31

    import :ava.util.Scanner;import :ava.io.  public void display()

      =  int sum64,:64;int c64;

      if(#64)  =  for(int i6;i#;i11)  =  sum6i;  :6i1;

    w!ile(sum#)  =  sum6sum1:;  :11;  >

    if(sum66#)

      =  for(int 6i;:;11)  =  if(66i)  System.out.print();  else  System.out.print(? 1 ?1);  >  System.out.println();  c11;  >  >  if(c664)  System.out.println(?T!ere are no Consecutive combinations of ?1#);  >  else  System.out.println(?I#$A%I& I#'T?);  >  public static void main(Strin0 ar0sH)t!rows I-@ception  =  Scanner sc 6new Scanner(System.in);  System.out.print(?-nter a number* ?);  int n6sc.ne@tInt();  ConsecutiveCombinations ob:6new ConsecutiveCombinations(n);  ob:.display();  >>

    6A"#A7L4

    5AM4

    2A$A$894 24&C"#9$#!5

    # int stores a number inputted by t!e user.

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    9/31

    n int stores a number.

    sum int stores t!e summation of consecutivecombination of numbers.

    i int a loop variable.

     : int stores t!e last number of consecutivecombinations.

    c int c!ecs w!et!er t!ere are any

    consecutive combinations or not.ob: ConsecutiveCombinations

    an ob:ect to call nonJstatic functions.

    #593$

    -nter a number* N!3$93$

    1 2 1 1 L 1 NL 1 N 1 MO 1 K

    #593$

    -nter a number* 44!3$93$

    7 1 4 1 1 2 1 1 L 1 N 1 MK 1 7 1 24 1 2 1 22

    #593$

    -nter a number* L!3$93$

     T!ere are no Consecutive combinations of L

    #593$

    -nter a number* J4!3$93$

    I#$A%I& I#'T

    Write a program in Java to accept a date and the first

    day of that year, and display the day of the given date.

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    10/31

      AL!"#$%M&

    Algorithm for void main()&tep '(  START.

    &tep )( Create a class ob:ect, ob:.

    &tep *( Call a function void accept().

    &tep +( -nd.

    Algorithm for void accept()&tep '(  Accept t!e re3uired date from user.

    &tep )(  a04.

    &tep *( C!ec for validity of @day, @mont!, @year, If true t!en +T Step L else print "I#$A%I&I#'T;

    &tep +( Accept Prst day of @year and c!ec for its validity.

    &tep ( Run a w!ile loop till sum# and repeat Step M.

    &tep -( sumsum1:, : :1.

    &tep ( If sum6# t!en print it.

    &tep /( 'rint "I#$A%I& I#'T.

    Algorithm for void compute()&tep '(  If @year5L64 t!en /H27.

    &tep )(  pos4.

    &tep *( Run a for loop from i4 till O.

    &tep +( posi.

    &tep ( Run a for loop from i4 till @mont!J and repeat Step M.

    &tep -( sumf&ays1@dayJ.

    &tep ( inde@(sumf&ays5O1pos)O

    &tep /( 'rint t!e re3uired day.

      2!C3M45$A$#!5

    import :ava.util.Scanner;import :ava.io.;  Strin0 &H6=?/#&AG?,?T-S&AG?,?--S&AG?,?TBRS&AG?,?ERI&AG?,?SATR&AG?,?S#&AG?>;

      &ate()

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    11/31

      = @day64;@mont!64;@year64;  day6??;

    >  public void accept()  = Scanner sc6new Scanner(System.in);

    System.out.print(?-nter t!e re3uired date in t!is formatU(dd mm yyyy) *J ?);  @day6sc.ne@tInt();  @mont!6sc.ne@tInt();  @year6sc.ne@tInt();  int a064;  if(@day6@day6 @mont!6@mont!62 @year6444@year67777)

      = if((@mont!662@year5L664 8(@day6@day627)) VV (@mont!662@year5L864 8(@day6@day62K)))  = System.out.println(?I#$A%I& I#'T?);  System.e@it(4);  >  System.out.print(?-nter t!e Prst date of year ?1@year1? * ?);  day6sc.ne@t();  for(int i64;iO;i11)  = if(&Hi.e3ualsI0noreCase(day))  = a06;  brea;  >  >

    if(a066)  compute();

      elseSystem.out.println(?I#$A%I& I#'T?);

      >  else  System.out.println(?I#$A%I& I#'T?);  >  public void compute()  =

    if(@year5L664)  /H627;  int pos64;  for(int i64;iO;i11)  = if(&Hi.e3ualsI0noreCase(day))  = pos6i;  brea;  >  >  int sumf&ays64;  for(int i64;i@mont!J;i11)  sumf&ays16/Hi;  sumf&ays16@dayJ;  int inde@6((sumf&ays5O)1pos)5O;  System.out.println(@day1?9?1@mont!1?9?1@year1? is on ?1&Hinde@);  >  public static void main(Strin0 ar0sH)  = &ate ob:6new &ate();  ob:.accept();  >>

    6A"#A7L4

    5AM4

    2A$A$894 24&C"#9$#!5

    @day int stores t!e day inputted by t!e user.

    @mont! int stores t!e mont! inputted by t!e user.

    @year int stores t!e year inputted by t!e user.

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    12/31

    day Strin0 stores t!e Prst date of t!e @year.

    /H int an array to store no.of days in 2 mont!s.

    &H Strin0 an array to store t!e days in a wee.

    a0 int an indicator of trut! values.

    i int a loop variable.

    pos int stores t!e position of t!e value of an array.

    sumf&ays int stores t!e summation of all t!e days before@day in a year.

    inde@ int stores t!e computed value of re3uired date.

    ob: &ate an ob:ect to call nonJstatic functions.

    #593$

    -nter t!e re3uired date in t!is formatU(dd mm yyyy) *J 7 4N 24N-nter t!e Prst date of year 24N * TBRS&AG

    !3$93$79N924N is on Tuesday

    #593$

    -nter t!e re3uired date in t!is formatU(dd mm yyyy) *J 4O 2 77M-nter t!e Prst date of year 77M * /#&AG!3$93$

    O92977M is on SATR&AG

    #593$

    -nter t!e re3uired date in t!is formatU(dd mm yyyy) *J 27 42 24M-nter t!e Prst date of year 24M * ERI&AG!3$93$

    2792924M is on /#&AG

    #593$

    -nter t!e re3uired date in t!is formatU(dd mm yyyy) *J 27 42 24N!3$93$

    I#$A%I& I#'T

    Write a program in Java to chec; whether a given

    number is a %appy number or not.

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    13/31

      AL!"#$%M&

    Algorithm for void main()&tep '(  START.

    &tep )( Create a class ob:ect, ob:.

    &tep *( Call a function void accept().

    &tep +( Call a function void isBappy().

    &tep ( -nd.

    Algorithm for void accept()&tep '(  Accept a number from user.

    Algorithm for void isHappy()&tep '(  acall a function sumUs3Udi0its and pass n.

    &tep )(  Run a w!ile loop till a7 and acall a function sumUs3Udi0its and pass a.

    &tep *( If a6 t!en print "BA''G #/Q-R else print "#T A BA''G #/Q-R.

    Algorithm for int sum_sq_digits(int x)&tep '(  If @64 t!en return 4.

    &tep )(  else d@54 and return d

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    14/31

      =  Scanner sc6new Scanner(System.in);  System.out.print(?-nter any number* ?);  n6sc.ne@tInt();  >  public void isBappy()  =  int a6sumUs3Udi0its(n);  w!ile(a7)  a6sumUs3Udi0its(a);

    if(a66)

      System.out.println(?BA''G #/Q-R?);  else  System.out.println(?#T A BA''G #/Q-R?);  >  public int sumUs3Udi0its(int @)  =  if(@664)  return 4;  else  =  int d6@54;  return (d  >

    public static void main(Strin0 ar0sH)

      =  Bappy ob:6new Bappy();

    ob:.accept();  ob:.isBappy();  >>

    6A"#A7L4

    5AM4

    2A$A$894 24&C"#9$#!5

    n int stores a number inputted by t!e user.

    a int stores t!e summation of di0its of n.

    @ int stores a number.

    d int stores t!e di0its of @.

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    15/31

    ob: Bappy an ob:ect to call nonJstatic functions.

    #593$

    -nter any number* 2K!3$93$

    BA''G #/Q-R

    #593$

    -nter any number* ML!3$93$

    #T A BA''G #/Q-R

    #593$

    -nter any number* MK!3$93$

    BA''G #/Q-R

    Write a program in Java to chec; whether a given '1

    digit code is a valid #&75 number or not.

      AL!"#$%M&

    Algorithm for void main()

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    16/31

    &tep '(  START.

    &tep )(  Read a Strin0 ss.

    &tep *( Create a class ob:ect, ob:.

    &tep +( Call a function void c!ec().

    &tep ( -nd.

    Algorithm for void chec()&tep '(  ls.len0t!().

    &tep )(  sum4, 4, a0.&tep *( If l64 t!en run a for loop from i4 till lJ , else +T Step .

    &tep +( abs.c!arAt(i).

    &tep ( If ab6LKab6NO t!en sumsum1

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    17/31

      if(ab6LKab6NO)  sum6sum1(  JJ;  >  ab6s.c!arAt(lJ);  if(ab66WXWVVab66W@W)  sum6sum1(

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    18/31

    ob: ISQ# an ob:ect to call nonJstatic functions.

    #593$

    -nter a 4 di0it code* 424N4K2!3$93$

    Sum of ISQ# code6 77Sum leaves no remainder, so it is a valid ISQ# code

    #593$

    -nter a 4 di0it code* 44OLM2NL2X!3$93$

    Sum of ISQ# code6 OMSum leaves no remainder, so it is a valid ISQ# code

    #593$

    -nter a 4 di0it code* 42L2K4!3$93$Sum of ISQ# code6 22Sum leaves remainder, so it is not a valid ISQ# code

    #593$

    -nter a 4 di0it code* N4NLX7LNL!3$93$

    I#$A%I& I#'T

    Write a program in Java to create a Magic &quare of 

    sin is between ' and ?.

    AL!"#$%M&

    Algorithm for void main()&tep '(  START.

    &tep )(  Create a class ob:ect, ob:.

    &tep *( Call a function void accept().

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    19/31

    &tep +( -nd.

    Algorithm for void accept()&tep '(  Accept t!e siYe of t!e matri@, n from user.

    &tep )(  If nVVnN t!en e@it t!e pro0ram after printin0 a messa0e.

    &tep *( /new intHnHn.

    &tep +( Call a function void compute().

    Algorithm for void compute()&tep '(  Run a loop from i4 to n and a nested loop from :4 to n and t!en /HiH:4.

    &tep )(  If n52864 t!en +T Step else +T Step M.

    &tep *( Run a w!ile loop till 6n  /6new intHnHn;  compute(); >  public void compute()  = int i,:,,t;  for(i64;in;i11)

      for(:64;:n;:11)

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    20/31

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    21/31

    -nter t!e siYe of t!e /atri@ * !3$93$

     T!e /a0ic /atri@ of siYe

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    22/31

      AL!"#$%M&

    Algorithm for void main()&tep '(  START.

    &tep )(  Read a number, siYe.

    &tep *( If siYe2 VV siYe4 t!en print ?TB- /ATRIX SIZ- IS T E RA#+-?.

    &tep +( else create a class ob:ect, ob:.

    &tep ( Call a function void accept().&tep -( Call a function void displayri0inal().

    &tep ( Call a function void rotate/atri@().

    &tep /( Call a function void displayRotated().

    &tep 0( Call a function void sumfCorner().

    &tep '1( -nd.

    Algorithm for void accept()&tep '(  Run a for loop from i4 to / and a nested loop from :4 to /.

    &tep )(  AHiH:6sc.ne@tInt().

    Algorithm for void display!riginal()&tep '(  print ?RI+I#A% /ATRIX?.

    &tep )(  Run a for loop from i4 to / and a nested loop from :4 to /.

    &tep *( print AHiH:1 ".

    &tep +( -nd loop.

    Algorithm for void rotateMatrix()&tep '(  4.

    &tep )(  Run a for loop from i4 to / and repeat Steps ,L .

    &tep *( /J.

    &tep +( Run a for loop from :4 to / and repeat Steps N,M .&tep ( QHiH:AHHi

    &tep -( if 4, J.

    &tep ( -nd loop.

    Algorithm for void display"otated()&tep '(  print ? /ATRIX AET-R RTATI#?.&tep )(  Run a for loop from i4 to / and a nested loop from :4 to /.

    &tep *( print QHiH:1 ".

    &tep +( -nd loop.

    Algorithm for void sum!fCorner()&tep '(  sumAH4H41AH4H/J1AH/JH/J1AH/JH4.

    &tep )(  print ?Sum of corner elements6 ?1sum.

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    23/31

      2!C3M45$A$#!5

    import :ava.util.Scanner;import :ava.io.  public void accept()  = Scanner sc6new Scanner(System.in);  System.out.println(?-nter elements of t!e /atri@?);  for(int i64;i/;i11)  for(int :64;:/;:11)  AHiH:6sc.ne@tInt();  >  public void displayri0inal()  = System.out.println(?RI+I#A% /ATRIX?);  for(int i64;i/;i11)  = for(int :64;:/;:11)

      System.out.print(AHiH:1? ?);

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    24/31

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    25/31

    -nter siYe of /atri@* -nter elements of t!e /atri@ 2 L N M O K 7!3$93$

    RI+I#A% /ATRIX 2 L N MO K 7/ATRIX AET-R RTATI#

    O L K N 27 M Sum of corner elements6 24

    #593$

    -nter siYe of /atri@* !3$93$

     TB- /ATRIX SIZ- IS T E RA#+-

    Write a program in Java to chec; whether a given

    number is a &mith 5umber or not.

      AL!"#$%M&

    Algorithm for void main()&tep '(  START.

    &tep )( Read a number n.

    &tep *( if n64 t!en create a class ob:ect, ob:.

    &tep +( Call a function void display().

    &tep ( else print ?I#$A%I& I#'T?.

    &tep -( -nd.

    Algorithm for void display()

    &tep '(  sumD

    sumDig(N).

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    26/31

    &tep )( sumEsum'rimeEact(#).

    &tep *( if sum&66sumE t!en print ?S/ITB #/Q-R?.

    &tep +( else print ?#T A S/ITB #/Q-R?.

    Algorithm for int sumDig(int n)&tep '(  s4.

    &tep )(  Run a w!ile loop till n864 and repeat Step .

    &tep *( ss1n54. nn94.

    &tep +( return s.

    Algorithm for int sum#rime$act(int n)&tep '(  i2 , s4.

    &tep )(  Run a w!ile loop till n and repeat Step .

    &tep *( if n5i64 t!en ss1sum&i0(i) , nn9I else ii1.

    &tep +( return s.

      2!C3M45$A$#!5import :ava.util.Scanner;import :ava .lan0.  public void display()  =  int sum&6sum&i0(#);  int sumE6sum'rimeEact(#);

      if(sum&66sumE)  System.out.println(?S/ITB #/Q-R?);  else

    System.out.println(?#T A S/ITB #/Q-R?);  >  public int sum&i0(int n)  =  int s64;  w!ile(n864)  =  s6s1(n54);  n6n94;  >  return s;

      >

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    27/31

      public int sum'rimeEact(int n)  =  int i62,s64;  w!ile(n)  =  if(n5i664)  =  s6s1sum&i0(i);  n6n9i;  >  else

      i11;  >  return s;  >  public static void main(Strin0 ar0sH)  =  Scanner sc6new Scanner(System.in);  System.out.print(?-nter a number* ?);  int n6sc.ne@tInt();  if(n64)  = Smit!#umber ob:6new Smit!#umber(n);

    ob:.display();  >  else  System.out.println(?I#$A%I& I#'T?);

      >>

    6A"#A7L4

    5AM4

    2A$A$894 24&C"#9$#!5

    # int stores a number inputted by t!e user.

    n int stores a number.

    sum& int stores t!e summation of di0its of #.

    sumE int stores t!e summation of prime factorsof #.

    s int stores t!e summation of di0its of n.

    i int a loop variable.

    ob: Smit!#umber an ob:ect to call nonJstatic functions.

    #593$

    -nter a number* MMM!3$93$

    S/ITB #/Q-R

    #593$

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    28/31

    -nter a number* L7OOON!3$93$

    S/ITB #/Q-R

    #593$

    -nter a number* 2!3$93$

    #T A S/ITB #/Q-R

    #593$

    -nter a number* J4!3$93$

    I#$A%I& I#'T

    Write a program in Java to chec; whether a given set of 

    elements form a &ymmetric Matri@ or not.

      AL!"#$%M&

    Algorithm for void main()&tep '(  START.

    &tep )(  Read a number, siYe.

    &tep *( Create a class ob:ect, ob:.

    &tep +( Call a function void accept().

    &tep ( Call a function void displayUri0inal().

    &tep -( Call a function void c!ecSymmetric().

    &tep ( Call a function void compute().

    &tep /( -nd.

    Algorithm for void accept()&tep '(  If M>2&&M

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    29/31

    &tep +( else print ?TB- /ATRIX SIZ- IS T E RA#+-? and e@it t!e pro0ram.

    Algorithm for void display_!riginal()&tep '(  print ?RI+I#A% /ATRIX?.

    &tep )(  Run a for loop from i4 to / and a nested loop from :4 to /.

    &tep *( print AHiH:1 ".

    &tep +( -nd loop.

    Algorithm for void chec%ymmetric()&tep '(  a0.

    &tep )(  Run a for loop from i4 to / and a nested loop from :4 to / and repeat Step .

    &tep *( if AHiH:86AH:Hi t!en a04.

    &tep +( if a06 t!en print ?TB- +I$-# /ATRIX IS SG//-TRIC?.

    &tep ( else print ?TB- +I$-# /ATRIX IS #T SG//-TRIC?.

    Algorithm for void compute()&tep '(  sum%&4, sumR&4.

    &tep )(  Run a for loop from i4 to / and a nested loop from :4 to / and repeat Steps .

    &tep *( if i6: t!en sum%&

    sum%&1AHiH:.&tep +( if i1:6/ t!en sumR&sumR&1AHiH:.

    &tep ( 'rint sum%&.

    &tep ( 'rint sumR&.

      2!C3M45$A$#!5

    import :ava.util.Scanner;

    class Symmetric= int AHH;  int /;  Symmetric(int siYe)  = /6siYe;  A6new intH/H/;

    >  public void accept()  = if(/2/4)  = Scanner sc6new Scanner(System.in);  System.out.println(?-nter elements of t!e /atri@?);  for(int i64;i/;i11)  = for(int :64;:/;:11)  AHiH:6sc.ne@tInt(); > >

    else  = System.out.println(?TB- /ATRIX SIZ- IS T E RA#+-?);  System.e@it(4); >

    >public void displayUri0inal()

      = System.out.println(?DnRI+I#A% /ATRIX?);  for(int i64;i/;i11)  = for(int :64;:/;:11)  System.out.print(AHiH:1? ?);

    System.out.println();>>

      public void c!ecSymmetric()  = int a06;  for(int i64;i/;i11)  = for(int :64;:/;:11)

      = if(AHiH:86AH:Hi)

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    30/31

      = a064;  brea; > > >  if(a066)  System.out.println(?TB- +I$-# /ATRIX IS SG//-TRIC?);  else  System.out.println(?TB- +I$-# /ATRIX IS #T SG//-TRIC?);  >  public void compute()  = int sum%&64,sumR&64;  for(int i64;i/;i11)  = for(int :64;:/;:11)

      = if(i66:)  sum%&16AHiH:;  if((i1:)66/)  sumR&16AHiH:; > >

    System.out.println(?T!e sum of t!e left dia0onal6 ?1sum%&);  System.out.println(?T!e sum of t!e ri0!t dia0onal6 ?1sumR&);  >  public static void main(Strin0 ar0sH)  = Scanner sc6new Scanner(System.in);  System.out.print(?-nter siYe of /atri@* ?);  int siYe6sc.ne@tInt();  Symmetric ob:6new Symmetric(siYe);  ob:.accept();  ob:.displayUri0inal();  ob:.c!ecSymmetric();

      ob:.compute();  >>

    6A"#A7L4

    5AM4

    2A$A$894 24&C"#9$#!5

    AHH int an array to store t!e elements of t!es3uare matri@.

    / int stores t!e siYe of t!e s3uare matri@ AHH.

    i int loop variable from 4 to /.

     : int anot!er loop variable from 4 to /.

    a0 int indicator to s!ow w!et!er t!e matri@ issymmetric or not.

    sum%& int stores t!e summation of elements of leftdia0onal of t!e matri@.

    sumR& int stores t!e summation of elements ofri0!t dia0onal of t!e matri@.

    ob: Symmetric an ob:ect to call nonJstatic functions.

    #593$

    -nter siYe of /atri@* -nter elements of t!e /atri@ 2 2 L N N M!3$93$

    RI+I#A% /ATRIX 2 2 L N

    N M

  • 8/16/2019 ISC COMPUTER PRACTICAL PROJECT FILE

    31/31

     TB- +I$-# /ATRIX IS SG//-TRIC T!e sum of t!e left dia0onal6  T!e sum of t!e ri0!t dia0onal6 4

    #593$

    -nter siYe of /atri@* L-nter elements of t!e /atri@O K 7 2 L N M K N O M L 2

    !3$93$RI+I#A% /ATRIXO K 7 2L N M K N O M L 2 TB- +I$-# /ATRIX IS #T SG//-TRIC T!e sum of t!e left dia0onal6 O T!e sum of t!e ri0!t dia0onal6 24

    #593$

    -nter siYe of /atri@* 4!3$93$ TB- /ATRIX SIZ- IS T E RA#+-