Lab Java 23/07/2556

July 23, 2013 12:37 pm Homework, Java, Private

Array lab1

public class LabArray_1 {
 
    public static void main(String[] args) {
        int[] number = {10,20,30,40,50};
        double sum=0;
            for (int i=0;i<=4;i++) {
                System.out.println("Score No:"+(i+1)+" >>>>"+number[i]);
                sum = sum+number[i];
            }
            System.out.println("Sum is "+sum);
    }
}


Array lab2

import java.util.Scanner;
 
public class Lab2 {
 
    public static void main(String[] args) {
 
        int a,c=0;
        Scanner a1 = new Scanner (System.in);
        Scanner b1 = new Scanner (System.in);
        System.out.print("Enter Number : ");
        a = a1.nextInt();
        int[] b = new int [a];
        for (int i=1;i<=a;i++) {
            System.out.print("Score No:"+i+">>>>> ");
            b[i-1] = b1.nextInt();
            c = c+b[i-1];
        }
        System.out.println("Sum is : "+c);
     }
  }

Array lab3

package lab3;
import java.util.Scanner;
 
/**
 *
 * @author kusumoto
 */
public class Lab3 {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int a,odd=0,even=0;
        Scanner a1 = new Scanner (System.in);
        Scanner b1 = new Scanner (System.in);
        System.out.print("Enter Line : ");
        a = a1.nextInt();
        int []c = new int [a];
        for (int i=1;i<=a;i++) {
            System.out.print("Enter Number ["+i+"] :");
            c[i-1] = b1.nextInt();
            if (c[i-1]%2==0) {
                odd=odd+c[i-1];
            } else {
                even=even+c[i-1];
            }
        }
        System.out.println("odd = "+odd+"     event = "+even);
    }
}