Advertisement
kadoel

Ganjil

Nov 9th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. /*
  2.  
  3. Function by : Kadoel Noesa
  4. Penggunaan : Ganjil(10)
  5. output : 1-3+5-7+9-11+13-15+17-19
  6.  
  7. */
  8.  
  9.  
  10. public class ganjil
  11. {
  12.     public static void main (String[]args)
  13.     {
  14.         int x,y,z;
  15.         y=10;
  16.         x=y*2;
  17.         z=1;
  18.         if (x%2==0)
  19.         {
  20.             System.out.print(z); System.out.print("");
  21.             for (y=1; y<x-1; y++)
  22.             {
  23.                
  24.                 System.out.print(" - ");
  25.                 System.out.print(y+2);
  26.                 y=y+2;
  27.                 System.out.print(" + ");
  28.                 System.out.print(y+2);
  29.                 y=y+1;
  30.                 if (y==x-4)
  31.                 {
  32.                     break;
  33.                 }
  34.             }
  35.            
  36.         }
  37.             System.out.print(" - ");
  38.             System.out.print(x-1);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement