Advertisement
kliersharon

תרגיל בית 4 -שרון קליר-מכינה תל אביב

Jun 13th, 2012
2,458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 2.36 KB | None | 0 0
  1. שאלה 1
  2. public class aboveX\4 {
  3.  
  4.     public aboveX() {
  5.         // TODO Auto-generated constructor stub
  6.     }
  7.  
  8.     /**
  9.      * @to count the numbers which are  bigger then x in an array
  10.      */
  11.     public static void main(String[] args) {
  12.        
  13.         int x=56;
  14.         int[]arrays={4,700,90,8,67,56,34};
  15.         int f=biggerThenx(x,arrays);
  16.         System.out.println( " there are "+f+" numbers above 56");
  17.     }
  18.     public static int biggerThenx(int b,int[]a){
  19.  int c=0;
  20.         for (int i=0;i<=a.length-1;i++)
  21.             if(a[i]>=b)
  22.                          
  23.             c++;
  24.         return c;
  25.                                                 }
  26.     }
  27.  
  28.  
  29. שאלה 2
  30.  
  31.  
  32.  
  33. public class aboveOneHundered\4 {
  34.  
  35.     /**
  36.      *
  37.      */
  38.     public static void main(String[] args) {
  39.  
  40.         int[]array={100,200,300,400,50,10,700};
  41.  
  42.         int x=aboveOnehun(array);
  43.  
  44.         System.out.print("the array has "  +x+ " numbers above 100");   }
  45.  
  46.     public static int aboveOnehun(int[]a)
  47.     {
  48.         int c=0;
  49.         for(int i=0;i<=a.length-1;i++)
  50.             if(a[i]>=100)
  51.                 c++;
  52.         return c;
  53.  
  54.                                             }
  55.  
  56.                                       }
  57.  
  58. שאלה 3
  59.  
  60. public class threeargu {
  61.  
  62.     /**
  63.      * @param args
  64.      */
  65.     public static void main(String[] args) {
  66.  
  67.         int[]arr={45,870,90,78,67,54,77,1001,1,9};
  68.         int n=35;
  69.         boolean f=true;
  70.         int d=checkTruefalse(f,arr,n);
  71.         System.out.println(d );
  72.  
  73.         // TODO Auto-generated method stub
  74.  
  75.     }
  76.  
  77.     public static int checkTruefalse(boolean x,int[]a,int t)
  78.     {
  79.  
  80.         int c=0;
  81.         for (int i=0;i<=a.length-1;i++)
  82.         {
  83.             if (x==true &&amp; a[i]>=t)                  
  84.                     c++;
  85.             else if(x==false &&amp; a[i]<=t)
  86.             c++;
  87.         }
  88.         return c;
  89.  
  90.     }
  91. }
  92.  
  93. שאלה 4
  94. public class stringMethod\4 {
  95.  
  96.     /**
  97.      * @param args
  98.      */
  99.     public static void main( String[] args)
  100.     {
  101.          String[] words= new String[5];
  102.         words[0]="Where";
  103.         words[1]="is";
  104.         words[2]="the";
  105.         words[3]="Birthday";
  106.         words[4]="cake?";
  107.          
  108.     String[]str1= new String[5];
  109.          str1=numberOfwords(words);
  110.             for(int i=0; i<=str1.length-1;i++)
  111.             {
  112.                System.out.print("  "+str1[i]);}
  113.              
  114.     }
  115.                                              
  116.        
  117.    
  118.     // TODO Auto-generated method stub
  119.  
  120.  
  121.    
  122.     public static String[] numberOfwords( String[] str )
  123.     {
  124.         for(int i=0;i<=str.length-1;i++)
  125.         {
  126.             if (str[i].length()-1>=4)
  127.                          
  128.              str[i]=str[i].toUpperCase();
  129.            
  130.             else str[i]=" ";
  131.            
  132.        
  133.    
  134.         }  
  135.  
  136.     return str;
  137.  
  138.  
  139.     }
  140.                               }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement