K16T1 Nhóm 1
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.


Hãy tưởng tượng, chúng ta đang cùng ở trên một con thuyền, tất cả đều phải cùng chèo để đưa con thuyền đến đích!
 
Trang ChínhGalleryLatest imagesTìm kiếmĐăng kýĐăng Nhập

Thông báo mới nhất, click vào để xem chi tiết: Đăng kí thành viên nhóm network!

Nhạc
Latest topics
» Assignment 02: Simple Calculating
by cambeme 18/10/2011, 23:50

» CHƯƠNG V: HỌC THUYẾT GIÁ TRỊ THẶNG DƯ - Trang 47-hết
by anhkhoamc083 5/10/2011, 08:51

» Bài tập SwingDemo
by cambeme 16/9/2011, 12:22

» ass3 cau 2
by nguyentam 29/5/2011, 10:46

» Assignment 09: Classes
by cambeme 27/5/2011, 17:57

» GROUP EXERCISE 03
by cambeme 24/5/2011, 18:23

» Bản kiểm điểm
by nhoc_vet 20/5/2011, 19:29

» Trình bày GROUP EXERCISE 02
by cambeme 20/5/2011, 00:01

» Khát là gì?
by cambeme 18/5/2011, 22:01

» Assignment 08: Methods
by cambeme 15/5/2011, 23:48

» GROUP EXERCISE 02
by cambeme 11/5/2011, 22:14

» Website nhóm 1
by cambeme 10/5/2011, 20:06

» Giao diện trang chủ
by cambeme 10/5/2011, 13:00

» Cấu hình DHCP RELAY AGENT - cấp cho 2 mạng LAN
by cambeme 9/5/2011, 23:59

» Slide 16
by cambeme 6/5/2011, 23:09

» Slide 15
by cambeme 6/5/2011, 23:08

» Slide 14
by cambeme 6/5/2011, 23:07

» Assignment 07: Control and Flow
by cambeme 6/5/2011, 22:33

» Trình bày GROUP EXERCISE 01
by cambeme 6/5/2011, 00:36

» GROUP EXERCISE 01
by cambeme 5/5/2011, 15:26

» Bai 1
by nguyentam 4/5/2011, 19:24

» cau thu 3
by cambeme 1/5/2011, 15:00

» day la bai so 2
by nguyentam 30/4/2011, 17:06

» chi tiet lam DNS
by nguyentam 30/4/2011, 16:40

» Tài liệu Windows Server 2003
by cambeme 30/4/2011, 08:40

» Phần mềm
by cambeme 29/4/2011, 12:35

» Công cụ tạo máy ảo VMware Workstation 7.1.4 Build 385546 Final
by cambeme 25/4/2011, 20:08

» Đề kiểm tra giữa kỳ Network
by cambeme 15/4/2011, 11:53

» Higher Computing Systems Networking
by cambeme 15/4/2011, 10:40

» Bài tập chương 6
by cambeme 12/4/2011, 17:41

No copy

Share | 
 

 Assignment 07: Control and Flow

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down 
Tác giảThông điệp
cambeme
Admin
Admin
cambeme


Giới tính Giới tính : Nam
Cung : Nhân Mã
Con giáp : Mùi
Bài gửi Bài gửi : 174
Điểm Điểm : 5242
Thanks Thanks : 0
Sinh nhật Sinh nhật : 05/12/1991
Ngày gia nhập Ngày gia nhập : 25/03/2011
Tuổi Tuổi : 32
Đến từ Đến từ : Thành phố Hồ Chí minh
Nghề nghiệp/ước mơ Nghề nghiệp/ước mơ : IT
Tâm trạng Tâm trạng : Hưng phắn
Châm ngôn sống Châm ngôn sống : Không có gì quý hơn hột vịt thịt kho!
Cao nhân tắt thở vô phương trị!


Assignment 07: Control and Flow Empty
Bài gửiTiêu đề: Assignment 07: Control and Flow   Assignment 07: Control and Flow I_icon_minitime6/5/2011, 22:33

Assignment 07: Control and Flow Titleb10 6/5/2011, 22:33 » Assignment 07: Control and Flow Assignment 07: Control and Flow Titleb12
Bài 1:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro01_MaxMin_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);// the scanner
        // declare the variable
        int a, b, max, min;
        // input the first number
        System.out.print("Nhap vao so thu nhat: ");
        a = input.nextInt();
        // input the second number
        System.out.print("Nhap vao so thu hai: ");
        b = input.nextInt();
        // use if function to calculate max and min
        if (a > b) {
            max = a;
            min = b;
        }// end if
        else {
            max = b;
            min = a;
        }// end else
            // print out the result
        System.out.println("MAX = " + max);
        System.out.println("MIN = " + min);
    }// end main function
}// end class
Bài 2:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh 
 * T094054
 */
public class cAss07Pro02_MaxOfFour_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);// the scanner
        // declare the variable
        int a = 0, b = 0, c = 0, d = 0, e = 0;
        // input the first number
        System.out.print("Nhap so thu nhat = ");
        a = in.nextInt();
        // input the second number
        System.out.print("Nhap so thu hai = ");
        b = in.nextInt();
        // input the third number
        System.out.print("Nhap so thu ba = ");
        c = in.nextInt();
        // input the forth number
        System.out.print("Nhap so thu tu = ");
        d = in.nextInt();
        // use if function to calculate the max number
        e = a;
        if (e < b) {
            e = b;
        }// end if
        if (e < c) {
            e = c;
        }// end if
        if (e < d) {
            e = d;
        }// end if
            // print out the result
        System.out.print("MAX = " + e);
    }// end main function
}// end class
Bài 3:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro03_MinOfFive_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);// the scanner
        // declare the variable
        int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
        // input the first number
        System.out.print("Nhap so thu nhat = ");
        a = in.nextInt();
        // input the second number
        System.out.print("Nhap so thu hai = ");
        b = in.nextInt();
        // input the third number
        System.out.print("Nhap so thu ba = ");
        c = in.nextInt();
        // input the forth number
        System.out.print("Nhap so thu tu = ");
        d = in.nextInt();
        // input the fifth number
        System.out.print("Nhap so thu nam = ");
        e = in.nextInt();
        // use if function to calculate the min number
        f = a;
        if (f > b) {
            f = b;
        }// end if
        if (f > c) {
            f = c;
        }// end if
        if (f > d) {
            f = d;
        }// end if
        if (f > e) {
            f = e;
        }// end if
            // print out the result
        System.out.print("MIN = " + f);
    }// end main function
}// end class
Bài 4:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro04_NegativeNumbers_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner keyboard = new Scanner(System.in);// the scanner
        // declare the variable
        int n, counter = 0;
        // input n from keyboard
        System.out.print("So phan tu cua mang: n = ");
        n = keyboard.nextInt();
        // declare the variable
        int[] arrValue = new int[n];
        // use if to calculate if n >0
        if (n > 0) {
            // use for to input n[i]
            for (int i = 0; i < n; i++) {
                // input A[n] from keyboard
                System.out.print("Nhap n[" + (i + 1) + "]: ");
                arrValue[i] = keyboard.nextInt();
                // use if to calculate how many number in the array <0
                if (arrValue[i] < 0) {
                    counter = counter + 1;
                }// end if
            }// end for
                // print out the result
            System.out.println("NoNs:" + counter);
        }// end if
        else {
            // print out the result when n <=0
            System.out.println("INVALID INPUT");
        }// end if
    }// end main function
}// end class
Bài 5:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro05_EvenCounter_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);// the scanner
        // declare the variable
        int n = 0, sum = 0, even = 0, odd = 0;
        // use for to input numbers and stop when it <0
        for (; n >= 0;) {
            System.out.print("Nhap so (dung lai khi am): ");
            n = input.nextInt();
            // use if to calculate if n>=0
            if (n >= 0) {
                sum = sum + 1;
                // use if to test if n is even number
                if ((n % 2) == 0) {
                    even = even + 1;
                }// end if
                else {
                    odd = odd + 1;
                }// end else
            }// end if
        }// end for
            // print out the result
        System.out.println("Total Number = " + sum);
        System.out.println("Even Numbers = " + even);
        System.out.println("Odd Numbers = " + odd);
    }// end main function
}// end class
Bài 6:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro06_ClassifyMe_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);// the scanner
        // declare the variable
        int n, S = 0;
        // input n from keyboard
        System.out.print("Nhap so n: ");
        n = input.nextInt();
        // use if to calculate if input >0
        if (n > 0) {
            // use for to calculate the sum of divisors of n
            for (int i = 1; i <= n; i = i + 1) {
                if (n % i == 0) {
                    S = S + i;
                }// end if
            }// end for
                // use if if S=2n
            if (S == 2 * n) {
                // print out the result when input is perfect number
                System.out.println("S = " + S + " = 2n so " + n
                        + " is perfect number.");
            }// end if
            else {
                // use if if S>2n
                if (S > 2 * n) {
                    // print out the result when input is abudant number
                    System.out.println("S = " + S + " > 2n so " + n
                            + " is abudant number.");
                }// end if
                    // use else if S<2n
                else {
                    // print out the result when input is deficient number
                    System.out.println("S = " + S + " < 2n so " + n
                            + " is deficient number.");
                }// end else
            }// end else
        }// end if
        else {
            // print out the result when input <=0
            System.out.println("INVALID INPUT");
        }// end else
    }// end main function
}// end class
Bài 7:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro07_PrimeNumber_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);// the scanner
        // declare the variable
        int n, S = 0;
        // input n from keyboard
        System.out.print("Nhap so n: ");
        n = input.nextInt();
        // use if to calculate if input >0
        if (n > 0) {
            // use for to calculate the number of divisors of n
            for (int i = 1; i <= n; i = i + 1) {
                if (n % i == 0) {
                    S = S + 1;
                }// end if
            }// end for
            if (S == 2) {
                // print out the result when input is prime number
                System.out.println("S = " + S + " so " + n
                        + " is prime number.");
            }// end if
            else {
                // print out the result when input is normal number
                System.out.println("S = " + S + " so " + n
                        + " is normal number.");
            }// end else
        }// end if
        else {
            // print out the result when input <=0
            System.out.println("INVALID INPUT");
        }// end else
    }// end main function
}// end class
Bài 8:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro08_NumberOfA_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);// the scanner
        // declare the variable
        String string;
        int counter = 0;
        // input the string from keyboard
        System.out.print("Nhap chuoi: ");
        string = input.nextLine();
        // use for to count how many time the word "A" appear in the string
        for (int i = 0; i < string.length(); i++) {
            if (string.charAt(i) == 'A') {
                counter = counter + 1;
            }// end if
        }// end for
            // print out the result
        System.out.println("So ky tu A trong chuoi: " + counter);
    }// end main function
}// end class
Bài 9:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro09_NumberOfXYZ_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);// the scanner
        // input the string from keyboard
        System.out.print("Nhap chuoi: ");
        String string = input.nextLine().trim();
        // declare the variable
        int n = 0;
        // use for to count the number of x,y,z appear in the string
        for (int i = 0; i < string.length(); i++) {
            if (XYZ(string.substring(i, i + 1))) {
                n++;
            }// end if
        }// end for
            // print out the result
        System.out.println("Tong so lan xuat hien cac ky tu x,y,z: " + n);
    }// end main function

    protected static boolean XYZ(String strVar) {
        final String KEY = "xXyYzZ";
        if (KEY.indexOf(strVar) != -1) {
            return true;
        }// end if
        return false;
    }
}// end class
Bài 10:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro10_NumberCounter_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);// the scanner
        // input the string from keyboard
        System.out.print("Nhap chuoi: ");
        String string = input.nextLine().trim();
        // declare the variable
        int n = 0;
        // use for to count the number of numbers appear in the string
        for (int i = 0; i < string.length(); i++) {
            if (Number(string.substring(i, i + 1))) {
                n++;
            }// end if
        }// end for
            // print out the result
        System.out.println("Tong so lan xuat hien cac chu so: " + n);
    }// end main function

    protected static boolean Number(String strVar) {
        final String KEY = "0123456789";
        if (KEY.indexOf(strVar) != -1) {
            return true;
        }// end if
        return false;
    }
}// end class
Bài 11:
Code:
import java.util.Scanner;

/*
 * @author Anh Trinh
 * T094054
 */
public class cAss07Pro11_StringOfNumber_T094054 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);// the scanner
        // input the string from keyboard
        System.out.print("Nhap chuoi: ");
        String string = input.nextLine().trim();
        // use for to calculate if only numbers appear in the string
        for (int i = 0; i < string.length(); i++) {
            if (Number(string.substring(i, i + 1))) {
                // print out the result
                System.out.println("NO");
                System.exit(0);
            }// end if
        }// end for
            // print out the result
        System.out.println("YES");
    }// end main function

    protected static boolean Number(String strVar) {
        final String KEY = "0123456789";
        if (KEY.indexOf(strVar) == -1) {
            return true;
        }// end if
        return false;
    }
}// end class



Assignment 07: Control and Flow Border11 Assignment 07: Control and Flow Border14
Về Đầu Trang Go down
https://nhom1.forum-viet.com
 

Assignment 07: Control and Flow

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang 

 Similar topics

-
» Assignment 09: Classes
» Assignment 01 – HelloWorld
» Assignment 05 – Imazing
» Assignment 08: Methods
» Assignment 03 – Swing Graphic
Trang 1 trong tổng số 1 trang

Permissions in this forum:Bạn không có quyền trả lời bài viết
K16T1 Nhóm 1 :: Các môn học :: Năm 1 :: Java-
Chuyển đến 
Đầu trang
Giữa trang
Cuối trang
Free forum | ©phpBB | Free forum support | Báo cáo lạm dụng | Thảo luận mới nhất