国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

《java 語言程序設(shè)計》第3、4章編程練習(xí)

2019-11-14 23:11:04
字體:
供稿:網(wǎng)友
java 語言程序設(shè)計》第3、4章編程練習(xí)

3.1

public class test {    public static void main(String[] args) {        System.out.

3.2

public class test {    public static void main(String[] args) {        System.out.println("Enter an integer: ");        Scanner input = new Scanner(System.in);        int n = input.nextInt();        System.out.print("Is " + n + " an even number? ");        if(n % 2 == 0)            System.out.println("true");        else            System.out.println("false");    }}

3.3

public class test {    public static void main(String[] args) {        System.out.print("Enter a, b, c, d, e, f: ");        Scanner input = new Scanner(System.in);        double a = input.nextDouble();        double b = input.nextDouble();        double c = input.nextDouble();        double d = input.nextDouble();        double e = input.nextDouble();        double f = input.nextDouble();        double fm = a * d - b * c;        if(fm == 0) {            System.out.println("The equation has no solution");        } else {            System.out.println("a is " + ((e * d - b * f) / fm) + " and y is " + ((a * f - e * c) / fm));        }    }}

3.4

public class test {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);        int a = (int)(Math.random() * 100);        int b = (int)(Math.random() * 100);        System.out.print("Enter the sum of the two integer(0~100): " + a + " and " + b + ": ");        int c = input.nextInt();        if(c == a + b)            System.out.println("True");        else            System.out.println("False");    }}

3.5

public class test {    public static int judge(int year, int month) {        boolean leap;        leap = (year % 4 ==0 && year % 100 != 0) || (year % 400 == 0);        if(month == 2) {            if(leap) return 29;            else return 28;        } else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {            return 31;        } else {            return 30;        }    }    public static void main(String[] args) {        String[] months = {" ", "January","February","March","April",                "May","June","July","August","September",                "October","November","December"};        System.out.print("Please inpit month and year: ");        Scanner input = new Scanner(System.in);        int month = input.nextInt();        int year = input.nextInt();        System.out.println(months[month] + " " + year + " has " + judge(year, month) + " days");    }}

4.7

public class test {    public static void main(String[] args) {double n = 10000;        double s1, s2, t;        s1 = s2 = 0;        t = 1;        final double rate = 0.05;        for(int i = 1;  i < 11; i++) {            t *= (1 + rate);        }        s1 = n * t;        System.out.println("s1 = " + s1);    }}

4.16

public class test {    public static void main(String[] args) {        System.out.print("Enter a number: ");        Scanner input = new Scanner(System.in);        int n = input.nextInt();        int i = 2;        while(true) {            while(n % i == 0 && n != i) {                System.out.print(i + ", ");                n /= i;            }            i++;            if(n == i) {                System.out.println(i);                break;            }        }    }}

4.25

public class test {    public static double countPi(int n) {        double pi = 0;        double t;        int m=1;        for(int i = 1; i < n; i++) {            t=1.0/(2*i-1);            t*=m;            pi+=t;            m*=-1;         }         pi *= 4;         return pi;    }        public static void main(String[] args) {        System.out.print("Enter a number: ");        Scanner input = new Scanner(System.in);        for(int i = 10000; i <= 100000; i++) {            System.out.println("pi(" + i + ") = " + countPi(i));;        }    }}

4.27

public class test {    public static boolean isLeapYear(int n) {        return ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0);    }        public static void main(String[] args) {        int n = 0;        for(int i = 2001; i < 2100; i++) {            if(isLeapYear(i)) {                n++;                if(n % 11 == 0) {                    System.out.println("/n");                } else {                    System.out.print(i + " ");                }                            }        }    }}

4.33

public class test {    public static boolean test(int n) {        int i, sum;        int m = n / 2;        sum = 0;        for(i = 1; i <= m; i++) {            if(n % i == 0)                sum += i;        }        if(sum == n)            return true;        else            return false;    }    public static void main(String[] args) {        for(int i = 2; i < 10000; i++) {            if(test(i))                System.out.print(i + "/n");        }    }}

4.41

public class test {    public static void main(String[] args) {        int n, count , max, t;        Scanner input = new Scanner(System.in);        System.out.println("Enter a number: ");        n = input.nextInt();        t = max = n;         count = 0;        while(t != 0) {            if(t > max) {                count = 1;                max = t;            } else {                count++;            }            System.out.println("Enter a number: ");            t = input.nextInt();        }        System.out.println("max= " + max + ", count= " + count);    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 土默特右旗| 元江| 新兴县| 迁安市| 舟山市| 宁陵县| 漠河县| 新邵县| 济源市| 榕江县| 赤城县| 义马市| 泰和县| 郯城县| 进贤县| 太原市| 叶城县| 惠来县| 正蓝旗| 札达县| 黄石市| 扎囊县| 徐州市| 迭部县| 富裕县| 宁陵县| 天门市| 绵竹市| 额济纳旗| 乾安县| 临邑县| 宁乡县| 阳高县| 榆社县| 泰兴市| 郧西县| 苏尼特右旗| 郑州市| 临湘市| 阳江市| 焉耆|