JAVA:如何使用if else之外的字符串值 [英] JAVA : how to use the string value outside the if else

查看:46
本文介绍了JAVA:如何使用if else之外的字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何实际使用String first_ param值并在if / else外面打印出来?



我尝试过:



how do i actually use the String first_ param value and print out at outside the if/else ?

What I have tried:

String sjcb_EM = jcb_EM.getSelectedItem().toString();
        
        if (sjcb_EM == "Evey Minute"){
            
            String first_param = "*";
        }

        System.out.println(first_param);

推荐答案

你需要DECLARE在if {...}块之外的first_param,并在里面设置它。



You need to DECLARE first_param outside the if { ... } block, and SET it inside.

String sjcb_EM = jcb_EM.getSelectedItem().toString();

        String first_param = "";
        
        if (sjcb_EM == "Evey Minute"){
            
            first_param = "*";
        }
 
        System.out.println(first_param);


在if语句之外声明它。如果你没有在它之外声明它,它只会在if语句中声明,并且无法被调用。
Declare it outside of the if statement. If you don't declare it outside of it, it will only be declared inside of the if statement and won't be able to be called on.


这篇关于JAVA:如何使用if else之外的字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆