Advertisement
Guest User

PokoCzopek

a guest
Nov 28th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. package testowyprogram;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.PrintWriter;
  5.  
  6. public class TestowyProgram {
  7.  
  8.     public static void main(String[] args) throws FileNotFoundException {
  9.        
  10.        
  11.          boolean weszlo = true;
  12.          int one = 0;
  13.          int last = 0;
  14.          
  15.         PrintWriter zapis = new PrintWriter("c:\\TEST\\test.txt");
  16.  
  17.         for (int i = 1000; i <= 9999; i++) {
  18.  
  19.             String test = Integer.toString(i);
  20.             char pierw = test.charAt(0);
  21.             int pierwInt = Character.getNumericValue(pierw);
  22.  
  23.             char drug = test.charAt(1);
  24.             int drugInt = Character.getNumericValue(drug);
  25.  
  26.             char trzy = test.charAt(2);
  27.             int trzyInt = Character.getNumericValue(trzy);
  28.  
  29.             char cztery = test.charAt(3);
  30.             int czteryInt = Character.getNumericValue(cztery);
  31.  
  32.        
  33.             if (pierwInt != 0 && drugInt != 0 && trzyInt != 0 && czteryInt != 0) {
  34.                 if (i % pierwInt == 0 && i % drugInt == 0 && i % trzyInt == 0 && i % czteryInt == 0) {
  35.                  
  36.                     if(weszlo == true){
  37.                      one = i;
  38.                     }
  39.                     weszlo = false;
  40.                    
  41.                     System.out.println(i);
  42.                     zapis.write(i+";");
  43.                      
  44.                      last = i;
  45.                      
  46.                 }
  47.             }
  48.  
  49.         } // popek żondzi
  50.  
  51.         zapis.close();  
  52.         System.out.println("Program znalazl liczby od "+one+"do"+last);
  53.  
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement