if(num == 1){
  // go to num1 == 1
}
if(num1 == 1){
  // to here
}
这只是一个示例代码而不是工作代码。我的问题的逻辑在代码中。
if(num == 1){
  // go to num1 == 1
}
if(num1 == 1){
  // to here
}
这只是一个示例代码而不是工作代码。我的问题的逻辑在代码中。
方法可以为您解决问题。它看起来像这样:
public void RunThis(int num)
{
     if (num == 1)
         NumIsOne();
     else
         //...
}
public void NumIsOne()    
{
     //...
}
这绝对不推荐 - 但是有一种goto,例如:
if(num == 1){
    here:
    for (int n = 0; n < 1; n++) {
        break here;
    }
}
ps:实际上下面的部分不起作用(向下跳或离开if块是不可能的):
如果(num1 == 1){ 这里: }
ps 这个站点正在展示GotoJava的实现。迷人的 ;)
方法示例
public class Testing{
public static void main(String[] args){
    int num1 = 0;
    if(num1 == 0){
        runMethod();
    }
}
public static void runMethod(){
    System.out.println("This will run");
}
}
那这个呢
    int num=1;
    int num1=0;
    if(num == 1){
        num1=1;
    }
    if(num1 == 1){
        System.out.println("so?");
    }