Linggo, Pebrero 12, 2012

basic act 8 : array . negative or positive



package javaapplication5;




public class JavaApplication5 {


   
    public static void main(String[] args) {
     int j = 9;
     int val[] = {1, 2, 3, 4, 5, 6, 7};
      
        for (int i = 0; i < val.length; i++) {
            
                    j -= val[i];
            
        }
        
        if(j >= 0){
            System.out.println("jolly");
        }        else
            System.out.println("not jolly");
    }
}

basic act 7 : array . carries



package javaapplication4;


public class JavaApplication4 {


    public static void main(String[] args) {
      


        int val[] = {1, 2, 3, 4, 5, 6, 7};
        int pe[] = {1, 2, 3, 4, 5, 6, 7};
        int x = 0;
        int y =0;
        for (int i = 0; i < val.length; i++) {
            x=0;
            x += val[i] +pe[i];
            if (x >= 10){
                y += 1;}
            
        }
    if (y == 0){
                System.out.println("no carries");  
    }
      else
            System.out.println(y + "carries");
        
    }
}