Don't like ads? PRO users don't see any ads ;-)
Guest

C17-II Q2

By: akskater100 on May 7th, 2012  |  syntax: Java  |  size: 1.21 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class Q2 {
  2.     public static boolean swing(int p, int q) {
  3.         return (p%q) == (p-(q*p/q));
  4.     }
  5.  
  6.     public static boolean polka(int p, int q) {
  7.         return (p%q) < (p-q);
  8.     }
  9.     public static void testA() {
  10.         for (int i = 1; i <= 10; i++) {
  11.             for (int j = 1; j <= 10; j++) {
  12.                 System.out.println("i: "+i+"\nj: "+j+"\n"+(swing(i,j)==polka(i,j)));
  13.             }
  14.         }
  15.     }
  16.     public static void testC() {
  17.         for (int i = 1; i <= 10; i++) {
  18.             for (int j = 1; j <= 10; j++) {
  19.                 if(i>=j)
  20.                 System.out.println("i: "+i+"\nj: "+j+"\n"+(swing(i,j)==polka(i,j)));
  21.             }
  22.         }
  23.     }
  24.     public static void testD() {
  25.         for (int i = 1; i <= 10; i++) {
  26.             for (int j = 1; j <= 10; j++) {
  27.                 if(i<j)
  28.                 System.out.println("i: "+i+"\nj: "+j+"\n"+(swing(i,j)==polka(i,j)));
  29.             }
  30.         }
  31.     }
  32.     public static void testE() {
  33.         for (int i = 1; i <= 10; i++) {
  34.             for (int j = 1; j <= 10; j++) {
  35.                 if(i%j==0)
  36.                 System.out.println("i: "+i+"\nj: "+j+"\n"+(swing(i,j)==polka(i,j)));
  37.             }
  38.         }
  39.     }
  40. }