Unit7.java.xhtml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * <https://y.st./>
  4. * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org./licenses/>.
  18. **/
  19. $xhtml = array(
  20. 'title' => '<code>Unit7.java</code>',
  21. 'subtitle' => 'Written in <span title="Programming 1">CS 1102</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on 2017-05-24',
  22. 'copyright year' => '2017',
  23. 'body' => <<<END
  24. <blockquote>
  25. <pre><code>/*
  26. * Copyright (C) 2017 Alex Yst
  27. *
  28. * This program is free software: you can redistribute it and/or modify
  29. * it under the terms of the GNU General Public License as published by
  30. * the Free Software Foundation, either version 3 of the License, or
  31. * (at your option) any later version.
  32. *
  33. * This program is distributed in the hope that it will be useful,
  34. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. * GNU General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU General Public License
  39. * along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
  40. */
  41. package unit7;
  42. /**
  43. * Alex Yst&apos;s CS 1102 (Programming 1) Unit 7 submission
  44. *
  45. * This class was programmed to fill the requirements on the Unit 7 programming
  46. * assignment in University of the People&apos;s CS 1102 (Programming 1) course.
  47. *
  48. * @author Alex Yst
  49. */
  50. public class Unit7 {
  51. /**
  52. * This method takes a hard-coded matrix, performs some checks on it, and
  53. * computes the value of the matrix. Were the matrix not hard-coded, it would
  54. * work on any matrix, as the rest of the code is flexible.
  55. *
  56. * @param arguments Not implemented
  57. */
  58. public static void main(String[] arguments) {
  59. int[][] m = {
  60. {10, 12, 11},
  61. { 9, 8, 31},
  62. { 2, 16, 24},
  63. };
  64. int numberOfRows = m.length;
  65. int numberOfColumns = 0;
  66. if(numberOfRows != 0) {
  67. for(int[] row: m) {
  68. numberOfColumns = row.length;
  69. if(numberOfColumns != numberOfRows) {
  70. System.out.println(&quot;This is not a square matrix.&quot;);
  71. return;
  72. }
  73. }
  74. }
  75. int total = 0;
  76. for(int i = 0;i &lt; numberOfColumns; i++) {
  77. total += m[i][numberOfColumns-1-i];
  78. }
  79. System.out.println(&quot;Value of secondary diagonal: &quot; + total);
  80. }
  81. }</code></pre>
  82. </blockquote>
  83. END
  84. );