Source code for submission s1000

Go to diff to previous submission

Mosquitko.java

  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  *
  7.  * @author student
  8.  */
  9. public class Mosquito {
  10.  
  11. /**
  12.   * @param args the command line arguments
  13.   */
  14. public static void main(String[] args) {
  15. Scanner sc = new Scanner(System.in);
  16. String res = sc.nextLine();
  17. List<Integer> result = new ArrayList<Integer>();
  18. int[] a = new int[7];
  19. int pom = 0;
  20. while (!"".equals(res)) {
  21. String[] ress = res.split(" ");
  22. for (int i = 0; i < ress.length; i++) {
  23. a[i] = Integer.parseInt(ress[i]);
  24. }
  25. try {
  26. if (a[6] > 0) {
  27. for (int i = 0; i < a[6]; i++) {
  28. pom = a[0];
  29. if (a[5] > 0) {
  30. a[0] = Math.round(a[1] / a[5]);
  31. } else {
  32. a[0] = a[1];
  33. }
  34. if (a[4] > 0) {
  35. a[1] = Math.round(a[2] / a[4]);
  36. } else {
  37. a[1] = a[2];
  38. }
  39. a[2] = pom * a[3];
  40.  
  41. }
  42. }
  43. } catch(ArithmeticException ex) {
  44. System.err.println(ex.toString());
  45. }
  46. result.add(a[0]);
  47. res = sc.nextLine();
  48. }
  49. for (Integer string : result) {
  50. System.out.println(string);
  51. }
  52.  
  53.  
  54. }
  55. }

Diff to submission s862

Mosquito.java

--- c4.s862.cteam124.mosquito.java.0.Mosquito.java
+++ c4.s1000.cteam124.mosquito.java.0.Mosquitko.java
@@ -1,9 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package mosquito;
-
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Scanner;
@@ -21,5 +15,5 @@
         Scanner sc = new Scanner(System.in);
         String res = sc.nextLine();
-        List<Integer> result = new LinkedList<Integer>();
+        List<Integer> result = new ArrayList<Integer>();
         int[] a = new int[7];
         int pom = 0;
@@ -29,20 +23,24 @@
                 a[i] = Integer.parseInt(ress[i]);
             }
-            if (a[6] > 0) {
-                for (int i = 0; i < a[6]; i++) {
-                    pom = a[0];
-                    if (a[5] > 0) {
-                        a[0] = Math.round(a[1] / a[5]);
-                    } else {
-                        a[0] = a[1];
-                    }
-                    if (a[4] > 0) {
-                        a[1] = Math.round(a[2] / a[4]);
-                    } else {
-                        a[1] = a[2];
-                    }
-                    a[2] = pom * a[3];
+            try {
+                if (a[6] > 0) {
+                    for (int i = 0; i < a[6]; i++) {
+                        pom = a[0];
+                        if (a[5] > 0) {
+                            a[0] = Math.round(a[1] / a[5]);
+                        } else {
+                            a[0] = a[1];
+                        }
+                        if (a[4] > 0) {
+                            a[1] = Math.round(a[2] / a[4]);
+                        } else {
+                            a[1] = a[2];
+                        }
+                        a[2] = pom * a[3];
 
+                    }
                 }
+            } catch(ArithmeticException ex) {
+                System.err.println(ex.toString());
             }
             result.add(a[0]);
@@ -55,3 +53,3 @@
 
     }
-}
+}
\ No newline at end of file