首页 > 代码库 > Day05_homework

Day05_homework

day05_01

package com.tedu.day05;

import java.util.Scanner;

public class Day05_01 {
    /*
     * 
     * */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
//        System.out.println("请输入一个整数:");
//        int a = scan.nextInt();
//        System.out.println("请输入一个小数:");
//        double b = scan.nextDouble();
//        double sum = getSum(a,b);
//        System.out.println("输入的数据之和:");
//        System.out.println(sum);
        System.out.println("输入一个整数:");
        int b = scan.nextInt();
//        printXing(a,b);
        mutiplyBlack(b);

    }
    
    //求输入的两个数之和
    public static double getSum(int a,double b){
        
        return a+b;
    }
    
    //打印m行n列的星形矩形
    public static void printXing(int n,int m){
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                System.out.print("* ");
            }
            System.out.println();
        }
        
    }
    
    //打印nn乘法表
    
    public static void mutiplyBlack(int n){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                System.out.print(i+"*"+j+"="+i*j+"\t");
            }
            System.out.println();
        }
    } 
}

day05_02

package com.tedu.day05;

public class Day05_02 {

    /**
     * (1)打印1到100之内的整数,但数字中包含9的要跳过 
     * (2)每行输出5个满足条件的数,之间用空格分隔
     */
    public static void main(String[] args) {
        printIntNumber();

    }

    public static void printIntNumber() {
        int count = 1;
        for (int i = 1; i < 101; i++) {
            if (i % 10 == 9 || i/10 ==9) {
                continue;
            } else {
                System.out.print(i+"\t");
                if (count % 5 == 0) {
                    System.out.println();
                }
                count++;
            }
        }
    }

}

day05_03

package com.tedu.day05;

public class Day05_03 {

    /**
     * 3.分析以下需求,并用代码实现:(封装成方法) (1)打印1-100之间的所有素数及个数 (2)每行输出5个满足条件的数,之间用空格分隔
     * 注意:大于1的能被1和其本身整除的数叫素数。
     */
    public static void main(String[] args) {
        printPrime();

    }

    public static void printPrime() {
        int count = 0; //素数的个数
        int con = 1;
        for(int num=2;num<101;num++){
            boolean flag = true;
            for(int i=2;i<num;i++){
                if(num % i == 0){
                    flag = false;
                }
            }
            if(flag){
                count++;
                System.out.print(num+"\t");
                if(con % 5 == 0){
                    System.out.println();
                }
                con++;
            }
            
        }
        
        
    }
}

 

Day05_homework