pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Advertising: online loans - mobile phones - loans - 3 mobile
Java paste-bin - collaborative debugging tool View Help

Posted by Anonymous on Tue 30th Oct 00:44 (modification of post by view diff)
download | new post

  1.  
  2. /**
  3. * Write a description of class Tablica here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class Tablica
  9. {
  10.     // instance variables - replace the example below with your own
  11.     private int rozmiar;
  12.     int [] tab;
  13.     int roz;
  14.  
  15.     /**
  16.      * Constructor for objects of class Tablica
  17.      */
  18.     public Tablica(int rozmiar)
  19.     {
  20.         this.rozmiar = rozmiar;
  21.         tab = new int [rozmiar];
  22.         roz = rozmiar - 1;
  23.     }
  24.    
  25.     public void ustawLosowo()
  26.     {
  27.         for(int i = 0; i < rozmiar; i++)
  28.         {
  29.             tab[i] = (int)(Math.random() * 10);
  30.         }
  31.     }
  32.    
  33.     public void wyswietlTablice()
  34.     {
  35.         System.out.println('\u000C');
  36.         for(int i = 0; i < rozmiar; i++)
  37.         {
  38.             System.out.println("tab[" + i + "] = " + tab[i]);
  39.         }
  40.     }
  41.    
  42.     public int sumaElementow()
  43.     {
  44.         int suma = 0;
  45.         for(int i = 0; i < rozmiar; i++)
  46.         {
  47.             suma += tab[i];
  48.         }
  49.         return suma;
  50.     }
  51.    
  52.     public void wartoscMaksymalna()
  53.     {
  54.         int indeks = 0;
  55.         int max = 0;
  56.         boolean czy = false;
  57.         for(int i = 0; i < rozmiar; i++)
  58.         {
  59.             if(tab[i] > max)
  60.             {
  61.                 indeks = i;
  62.                 max = tab[i];
  63.                 czy = true;
  64.             }
  65.         }
  66.         if(!czy)
  67.         {
  68.             System.out.println("Nie znaleziono wartości maksymalnej.");
  69.         }
  70.         else
  71.         {
  72.             System.out.println("Wartosc maksymalna to " + max + " a jej indeks to: " + indeks);
  73.         }
  74.     }
  75.    
  76.     public int wartMaks()
  77.     {
  78.         int indeks = 0;
  79.         int max = 0;
  80.         boolean czy = false;
  81.         for(int i = 0; i < rozmiar; i++)
  82.         {
  83.             if(tab[i] > max)
  84.             {
  85.                 indeks = i;
  86.                 max = tab[i];
  87.                 czy = true;
  88.             }
  89.         }
  90.         return max;
  91.     }
  92.  
  93.     public boolean czyWystepuje(int wartosc, int k)
  94.     {
  95.         boolean czy = false;
  96.         for(int i = 0; i < k; i++)
  97.         {
  98.             if(tab[i] == wartosc)
  99.             {
  100.                 return true;
  101.             }
  102.         }
  103.         return czy;
  104.     }
  105.  
  106.     public boolean czyRoznowartosciowa()
  107.     {
  108.         boolean jest = true;
  109.         for(int i = 0; i < rozmiar && jest; i++)
  110.         {
  111.             for( int j=i+1; j < rozmiar && jest ; j++)
  112.             {
  113.                 jest=tab[i] != tab[j];
  114.             }
  115.         }
  116.         return jest;
  117.     }
  118.    
  119.     public void usunWartosc(int wartosc)
  120.     {
  121.         for(int i = 0; i < rozmiar; i++)
  122.         {
  123.             if(tab[i] == wartosc)
  124.             {
  125.                 tab[i] = tab[rozmiar - 1];
  126.                 rozmiar--;
  127.             }
  128.         }
  129.     }
  130.    
  131.     public void usunPowtorzenia()
  132.     {
  133.         boolean jest = true;
  134.         for(int i = 0; i < rozmiar && jest; i++)
  135.         {
  136.             for( int j=i+1; j < rozmiar && jest; j++)
  137.             {
  138.                 jest=tab[i] != tab[j];
  139.                 if(!jest) tab[j] = tab[rozmiar - 1];
  140.                 jest = true;
  141.                 rozmiar--;
  142.             }
  143.         }
  144.     }
  145.    
  146.     /*
  147.      *
  148.     public void usunPowtorzenia()
  149.     {
  150.         boolean jest = true;
  151.         for(int i = 0; i < rozmiar && jest; i++)
  152.         {
  153.             for( int j=i+1; j < rozmiar && jest; j++)
  154.             {
  155.                 jest=tab[i] != tab[j];
  156.                 if(!jest) tab[i] = tab[rozmiar - 1];
  157.                 tab[rozmiar - 1] = 0;
  158.                 jest = true;
  159.                 rozmiar--;
  160.             }
  161.         }
  162.     }
  163.     */
  164.  
  165.        
  166.  
  167. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me
: