会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133544个问题

老师看一下,我这个双色球代码?我测试了一下,电脑自动抽奖没有一次中的,是不是写的有问题

package Javach04.com.bjsxt.array;
import java.util.Scanner;
import java.util.Arrays;
/**
 * @author xiaoding
 *    双色球项目
 */
public class Test9 {
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        
        
        
        Ball[] arry01 = new Ball[7];        //购买的彩色球号码
        Ball[] arry02 = new Ball[7];        //开奖号码
        
        int i;                    //输入号码
        int numPrice = 2;        //每注金额
        int bettingPice = 0;    //投注次数
        int redNum = 0;            //红色球
        int lanNum = 0;            //蓝色球
        
        while(true) {
            System.out.println("*****************欢迎进入双色球彩票系统*****************");
            System.out.println("1.购买彩票");
            System.out.println("2.查看开奖");
            System.out.println("3.退出");
            System.out.println("*******************************************************");
            System.out.println("请选择菜单:");
    
            if (input.hasNextInt()) {
                i = input.nextInt();
                switch(i) {
                    case 1:
                        System.out.println("======欢迎购买双色球======");
                        System.out.println("     人工摇号:选择1");
                        System.out.println("     机器摇号:选择2");
                        while(true) {
                            i = input.nextInt();
                            if (i == 1) {
                                artificial(arry01);
                                System.out.println();
                                System.out.println("投注次数");
                                bettingPice = input.nextInt();
                                break;
                            }else if (i == 2){
                                machine(arry01);
                                System.out.println();
                                System.out.println("投注次数");
                                bettingPice = input.nextInt();
                                break;
                            }else {
                                System.err.println("输入有误,请重新输入");
                                System.out.println("======欢迎购买双色球======");
                                System.out.println("     人工摇号:选择1");
                                System.out.println("     机器摇号:选择2");
                                continue;
                            }
                        }
                        break;
                    case 2:
                        lottery(arry02,arry01,bettingPice,redNum,lanNum);
                        break;
                    case 3:
                        System.out.println("退出双色球彩票系统");
                        System.exit(0);
                        break;
                    default:
                        System.err.println("选择不对,请重新输入");
                        break;
                }
            }else {
                String num1 = input.next();
                System.err.println("输入有误,请重新输入");
            }
        }
    }
    
    /*
     * 人工购买双色球:
     */
    public static void artificial(Ball[] arry01) {
        System.out.println("红色球是:1~33个,蓝色球是:1~16个");
        String name = "红色球";
        int number;
        for (int i = 0;i<arry01.length;i++) {
            if (i<6) {
                System.out.println("请选择第一" + i + "个" + name + "号码");
                while(true) {
                    number = input.nextInt();
                    if ((number >= 1) && (number <= 33)) {
                        break;
                    }else {
                        System.err.println("输入有误,请重新输入");
                    }
                }
                arry01[i] = new Ball(name,number);
            }else {
                String name2 = "蓝色球";
                System.out.println("请输入篮色球号码:");
                while(true) {
                    number = input.nextInt();
                    if ((number >= 1) && (number <= 16)) {
                        break;
                    }else {
                        System.err.println("输入有误,请重新输入");
                    }
                }
                arry01[6] = new Ball(name2,number); 
                System.out.print(Arrays.toString(arry01) + " ");
            }
        }    
    }
    
    /*
     * 机器自动摇号
     */
    public static void machine(Ball[] arry01) {
        System.out.println("红色球是:1~33个,蓝色球是:1~16个");
        String name = "红色球";
        int number;
        for (int i = 0;i<arry01.length;i++) {
            if (i<6) {
                number = (int)(Math.random() * (34 - 1) + 1);
                for (int j = 0;j<arry01.length - 1;j++) {
                    if ((arry01[j] != null) && (arry01[j].getNum() == number)) {
                        arry01[i--] = null;
                        break;
                    }
                }
                arry01[i] = new Ball(name,number);
            }else {
                String name2 = "蓝色球";
                number = (int)(Math.random() * (17 - 1) + 1);
                arry01[6] = new Ball(name2,number);
            }
        }
        System.out.print(Arrays.toString(arry01) + " ");
    }
    
    
    /*
     *     开奖系统
     */
    
    public static void lottery(Ball[] arry02,Ball[] arry01,int bettingPice,int redNum,int lanNum) {
        //系统自动抽取中奖双色球号
        String name = "红色球";
        int number;
        for (int i = 0;i<arry02.length;i++) {
            if (i<6) {
                number = (int)(Math.random() * (34 - 1) + 1);
                for (int j = 0;j<arry02.length - 1;j++) {
                    if ((arry02[j] != null) && (arry02[j].getNum() == number)) {
                        arry02[i--] = null;
                        break;
                    }
                }
                arry02[i] = new Ball(name,number);
            }else {
                String name2 = "蓝色球";
                number = (int)(Math.random() * (17 - 1) + 1);
                arry02[6] = new Ball(name2,number);
            }
        }
        
        //判断是否中奖
        for (int k = 0;k<arry01.length;k++) {
            if (k<6) {
                for (int m = 0;m<arry02.length - 1;m++) {
                    if (arry01[k].equals(arry02[m])) {
                        redNum++;
                    }
                }
            }else {
                if (arry01[k].equals(arry02[k])) {
                    lanNum++;
                }
            }
        }
        
        //判断中奖等级
        System.out.println("您购买的号码为:" + Arrays.toString(arry01));
        System.out.println("本其中奖号码为:" + Arrays.toString(arry02));
        if (redNum == 6 && lanNum == 1) {
            System.out.println("一等奖:" + " 一共下注了" + bettingPice  + "次,一次2元" + "  奖金:" + bettingPice * 500 + "万");
        }else if (redNum == 6 && lanNum == 0) {
            System.out.println("二等奖:" + " 一共下注了" + bettingPice  + "次,一次2元" + "  奖金:" + bettingPice * 400 + "万");
        }else if (redNum == 5 && lanNum == 1) {
            System.out.println("三等奖:" + " 一共下注了" + bettingPice  + "次,一次2元" + "  奖金:" + bettingPice * 100 + "万");
        }else if ((redNum == 4 && lanNum == 1) || ((redNum == 5) && (lanNum == 0))) {
            System.out.println("四等奖:" + " 一共下注了" + bettingPice  + "次,一次2元" + "  奖金:" + bettingPice * 10000 + "万");
        }else if ((redNum == 3 && lanNum == 1) || ((redNum == 4) && (lanNum == 0))) {
            System.out.println("五等奖:" + " 一共下注了" + bettingPice  + "次,一次2元" + "  奖金:" + bettingPice * 1000 + "千");
        }else if (redNum <= 2 && lanNum == 1) {
            System.out.println("六等奖:" + " 一共下注了" + bettingPice  + "次,一次2元" + "  奖金:" + bettingPice * 5 + "元");
        }else {
            System.out.println("很遗憾没有中奖");
        }
        
    }
    
}

class Ball {
    String name;    //球
    int num;        //双色球值
    private Ball[] arry01;
    
    public String getName() {
        return name;
    }
    public void pzice() {
        // TODO Auto-generated method stub
        
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getNum() {
        return num;
    }
    public void setNum(int num) {
        this.num = num;
    }
    
    Ball() {}
    public Ball(String name,int num) {
        this.name = name;
        this.num = num;
    }
    public Ball(int num) {
        this.num = num;
    }
    
    //从写toString方法
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return "" + getNum();
    }
    
    //从写equals方法
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }else{
            if (obj instanceof Ball) {
                Ball man = (Ball) obj;
                if (this.num == man.num) {
                    return true;
                }
            }
        }
        return false;
    }
    
    
}


JAVA 全系列/第一阶段:AI驱动的JAVA编程/数组和数据存储 37126楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 37130楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/面向对象详解和JVM底层内存分析 37131楼
Python 全系列/第二十三阶段:人工智能基础_机器学习理论和实战(旧)/XGBoost算法 37132楼
Python 全系列/第四阶段:函数式编程和核心特性/生成器、迭代器、动态性 37138楼

老师,您好!为什么我注入不了addUserService呢,出现了如下报错:


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of @Reference dependencies is failed; nested exception is java.lang.IllegalStateException: zookeeper not connected

at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:146) ~[spring-context-support-1.0.6.jar:na]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1427) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]

at com.bjsxt.consumer.UserConsumerApplication.main(UserConsumerApplication.java:10) [classes/:na]

Caused by: java.lang.IllegalStateException: zookeeper not connected

at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.<init>(CuratorZookeeperClient.java:83) ~[dubbo-remoting-zookeeper-2.7.6.jar:2.7.6]

at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter.createZookeeperClient(CuratorZookeeperTransporter.java:26) ~[dubbo-remoting-zookeeper-2.7.6.jar:2.7.6]

at org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperTransporter.connect(AbstractZookeeperTransporter.java:70) ~[dubbo-remoting-zookeeper-2.7.6.jar:2.7.6]

at org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter$Adaptive.connect(ZookeeperTransporter$Adaptive.java) ~[dubbo-common-2.7.6.jar:2.7.6]

at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfiguration.<init>(ZookeeperDynamicConfiguration.java:70) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfigurationFactory.createDynamicConfiguration(ZookeeperDynamicConfigurationFactory.java:37) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory.lambda$getDynamicConfiguration$0(AbstractDynamicConfigurationFactory.java:39) ~[dubbo-common-2.7.6.jar:2.7.6]

at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_101]

at org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory.getDynamicConfiguration(AbstractDynamicConfigurationFactory.java:39) ~[dubbo-common-2.7.6.jar:2.7.6]

at org.apache.dubbo.common.config.configcenter.DynamicConfiguration.getDynamicConfiguration(DynamicConfiguration.java:223) ~[dubbo-common-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.bootstrap.DubboBootstrap.prepareEnvironment(DubboBootstrap.java:857) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.bootstrap.DubboBootstrap.startConfigCenter(DubboBootstrap.java:603) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.bootstrap.DubboBootstrap.useRegistryAsConfigCenterIfNecessary(DubboBootstrap.java:671) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.bootstrap.DubboBootstrap.initialize(DubboBootstrap.java:509) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.bootstrap.DubboBootstrap.init(DubboBootstrap.java:494) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:190) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:158) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.getOrCreateProxy(ReferenceAnnotationBeanPostProcessor.java:274) ~[dubbo-2.7.6.jar:2.7.6]

at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:143) ~[dubbo-2.7.6.jar:2.7.6]

at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.getInjectedObject(AbstractAnnotationBeanPostProcessor.java:359) ~[spring-context-support-1.0.6.jar:na]

at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor$AnnotatedFieldElement.inject(AbstractAnnotationBeanPostProcessor.java:539) ~[spring-context-support-1.0.6.jar:na]

at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:142) ~[spring-context-support-1.0.6.jar:na]

... 18 common frames omitted

Caused by: java.lang.IllegalStateException: zookeeper not connected

at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.<init>(CuratorZookeeperClient.java:80) ~[dubbo-remoting-zookeeper-2.7.6.jar:2.7.6]

... 40 common frames omitted



目前来看主要是这段代码注入不了,麻烦老师看看image.png

JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 37139楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637