啊对对对对对......

啊对对对对对......,第1张

package com.qiku.Test;

public class Test01 {
   // 1、打印九九乘法表。
    public static void main(String[] args) {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i ; j++) {
                System.out.print(j + "*"+i + "="+ i*j+"\t");
            }
            System.out.println();
        }
    }
}
package com.qiku.Test;

import java.util.Scanner;

public class Test02 {
    public static void main(String[] args) {
        /**
         * 2、猜数字游戏:随机生成数字n(1-100), 等待用户输入猜测数据, 根据用户的输入比较输出
         * 	猜大了,猜小了,猜对了, 如果用户猜对了就结束游戏
         */
        System.out.println("=====游戏开始=====");
        System.out.println("友情提示:如果您想中途退出游戏,请输入一个不大于0的数组即可");
        int randomNum = (int) (Math.random() * 100 + 1);//系统生成随机数
        System.out.println("随机数为:" + randomNum);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数:");

        while(true){
            int inputNum = sc.nextInt();//玩家输入数字
            if (inputNum > randomNum && inputNum > 0){
                System.out.println("数字猜测错误,比随机数大哦");
            }else if (inputNum < randomNum && inputNum > 0){
                System.out.println("数字猜测错误,比随机数小哦");
            }else if (inputNum == randomNum && inputNum > 0){
                System.out.println("恭喜你猜测正确,游戏结束");
                break;
            }
            if (inputNum <= 0){
                System.out.println("是否退出游戏?");//添加中途退出游戏条件
                System.out.println("0.退出    1.继续"   );
                System.out.println("请输入数字:0 或者 1");
                int num = sc.nextInt();
                switch (num){
                    case 0:
                        System.out.println("游戏已退出,欢迎下次游玩");
                        break;
                    case 1:
                        System.out.println("游戏继续...");
                }
                if (num==0){
                    break;
                }if (num==1){
                    continue;
                }
            }
        }
    }
}
package com.qiku.Test;

public class Test03 {
    public static void main(String[] args) {
        /**
         * 3、编写程序,求0-100之间的所有的素数;
         *   素数:只能被1及其本身整除的数
         */
        boolean isflag;
        for (int i =2; i <100 ; i++) {
           isflag = true;//给进来的每个元素定义标志
            for (int j = 2; j <= Math.sqrt(i); j++) {//Math.sqrt 算术平方根
                if (i % j ==0){
                    isflag = false;
                    break;
                }
            }
            if (isflag){
                System.out.print(i+" ");
            }
        }
    }
}
package com.qiku.Test;

import java.util.Arrays;

public class Test04 {
    public static void main(String[] args) {
        //4、生成一个包含10元素的随机数组,元素的取值范围:10-90,并使用冒泡排序给该数组升序排列
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int)(Math.random()*81+10);
        }
        System.out.println(Arrays.toString(arr));//获取初始数组
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if (arr[j] > arr[j+1]) {
                    int temp = arr[j];//两个元素的交换
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
package com.qiku.Test;
//如果错了,还请帮忙说哪里错了,万分感谢

public class Test05 {
    //5、自已设计一个单例模式
    public static void main(String[] args) {
        //Person person = new Person();不允许创建对象
        Person.setAge(13);
        System.out.println(Person.getAge());
        int p1 =Person.getAge();
        int p2 = Person.getAge();
        System.out.println(p1==p2);

    }
}
class  Person{
    private static int age;
    private static String name;

    private Person() {
    }

    private Person(int age, String name) {//构造器私有化
        this.age = age;
        this.name = name;
    }
    private static Person person = new Person(12,"张三");

    public static int getAge() {
        return age;
    }

    public static void setAge(int age) {
        Person.age = age;
    }

    public static String getName() {
        return name;
    }

    public static void setName(String name) {
        Person.name = name;
    }
}
package com.qiku.Test;

import java.util.ArrayList;
import java.util.List;

public class Test06 {
    public static void main(String[] args) {
        /**
         * 6、编写程序,模拟验证码,要求:
         *   a、验证码由5个字符组成
         *   b、组成验证码的字符只能是字母或者数字
         *   c、字符不能重复
         */
        String str = "1234567890";
        String lowerCase = "qwertyuiopasdfghjklzxcvbnm";
        String upperCase = lowerCase.toUpperCase();
        String all = str+lowerCase+upperCase;
        List list = new ArrayList();
        for (int i = 0; i < all.length(); i++) {
            list.add(all.charAt(i));
        }
        System.out.println(list);
        String verificationCode = "";//定义验证码
        for (int i = 0; i < 5; i++) {
            int random = (int)(Math.random()*list.size());
            verificationCode += list.get(random);
            list.remove(random);
        }
        System.out.println(verificationCode);
    }
}
public class Test07 {
    /**
     * 选择题
     * 1-10 :B   D   B   D   D
     * D   A   D   C   D
     * 11-15:B  D   C   D   D
     * 判断题1-10 F    T   T   F   T
     * F   F   T   F   T
     */

}
//1-5		BCBDD   -2
//6-10	DADCD
//11-15	BDCDD
//1、错
//2、对
//3、对
//4、对   -2
//5、对
//6、错
//7、对   -2
//8、对
//9、错
//10、对

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/731971.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存