SeanNers

PhepChiaHet

Aug 19th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class PhepChiaHet {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.        
  7.         PhepChiaHet check1 = new PhepChiaHet();
  8.         PhepChiaHet check2 = new PhepChiaHet();
  9.         PhepChiaHet check3 = new PhepChiaHet();
  10.        
  11.         boolean isTrue = false;
  12.         int testLine = input.nextInt();
  13.         int[] nhap = new int[ testLine * 2 ];
  14.         int[] sum = new int[123];
  15.        
  16.         //
  17.         for( int i = 1 ; i <= (testLine + 1) ; i++ ) {
  18.             nhap[i] = input.nextInt();
  19.             /*Take the second number and the first and assign it with start and end. Begin loop to check, if 1 condiction is true
  20.              * then sum++. After checking all number, print sum then takes the third and fouth.
  21.              */
  22.             if( i % 2 == 0 ) {
  23.                 int end = nhap[i];
  24.                 //If there sum++ then print the sum else print 0
  25.                 for( int start = nhap[i - 1]; start <= end ; start++ ) {
  26.                     if( check1.chiaHet156no4(start) || check2.chiaHet415no6(start) || check3.chiaHet46no15(start) ) {
  27.                         sum[i]++;
  28.                         isTrue = true;
  29.                     }
  30.                 }
  31.             }
  32.            
  33.             if(isTrue) isTrue = false;
  34.             else sum[i] = 0;
  35.         }
  36.        
  37.         for( int j = 1 ; j <= (testLine + 1) * 2 ; j++ ) {
  38.             if ( j % 2 == 0 ) System.out.println(sum[j]);
  39.         }
  40.        
  41.        
  42.     }
  43.    
  44.     //Check boolean ONLY 2 OUT OF 3 will return TRUE
  45.    
  46.     public boolean chiaHet46no15(int input) {
  47.         boolean isChiaHet4 = false;
  48.         boolean isChiaHet6 = false;
  49.         boolean isChiaHet15 = false;
  50.         boolean isRight = false;
  51.         if( input % 4 == 0 ) isChiaHet4 = true;
  52.         if( input % 6 == 0 ) isChiaHet6 = true;
  53.         if( input % 15 != 0 ) isChiaHet15 = true;
  54.         if( isChiaHet4 && isChiaHet6 && isChiaHet15 ) isRight = true;
  55.         return isRight;
  56.     }
  57.    
  58.     public boolean chiaHet415no6(int input) {
  59.         boolean isChiaHet4 = false;
  60.         boolean isChiaHet6 = false;
  61.         boolean isChiaHet15 = false;
  62.         boolean isRight = false;
  63.         if( input % 4 == 0 ) isChiaHet4 = true;
  64.         if( input % 6 != 0 ) isChiaHet6 = true;
  65.         if( input % 15 == 0 ) isChiaHet15 = true;
  66.         if( isChiaHet4 && isChiaHet6 && isChiaHet15 ) isRight = true;
  67.         return isRight;
  68.     }
  69.    
  70.     public boolean chiaHet156no4(int input) {
  71.         boolean isChiaHet4 = false;
  72.         boolean isChiaHet6 = false;
  73.         boolean isChiaHet15 = false;
  74.         boolean isRight = false;
  75.         if( input % 4 != 0 ) isChiaHet4 = true;
  76.         if( input % 6 == 0 ) isChiaHet6 = true;
  77.         if( input % 15 == 0 ) isChiaHet15 = true;
  78.         if( isChiaHet4 && isChiaHet6 && isChiaHet15 ) isRight = true;
  79.         return isRight;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment