2016-02-19 102 views
1
  1. 这段代码是用于日食学习课程的,我们的老师出来了,有人可以解释错误,谢谢。我们试图在数组中的循环内创建一个循环。

package Wrok;我如何修复这个循环在Java Eclipse中的数组循环中?

import java.util.Random; 

public class Victory { 
    public static void main(String[] args) { 
     // TODO Auto-generated method stub 
     Random ran = new Random(); 
     double x = ran.nextInt(6) + 5; 
     Random ran1 = new Random(); 
     double y = ran.nextInt(6) + 5; 
     int Time = -1; 
     double[][] hello = new double [2][2]; 
       hello[0][0]= 1; 
       hello[0][1]= 2; 
       hello[1][0]= 3; 
       hello[1][1]= 4; 
     for (int i = 0; i<Time; i++){ 
      for (int j = 0; j<Time; j++){ 
       if(ran = 0){ 
        if (ran1 = 0){ 
         System.out.println(hello[0][0]); 
        } 
       } 
       if(ran = 1){ 
        if (ran1 = 0){ 
         System.out.println(hello[1][0]); 
        } 
       } 
       if(ran = 0){ 
        if (ran1 = 1){ 
         System.out.println(hello[0][1]); 
        } 
       } 
       if(ran = 1){ 
        if (ran1 = 1){ 
         System.out.println(hello[1][1]); 
        } 
       } 
      } 
     } 
    } 
} 
+0

'我<时间'和'时间= -1'。锄头经常会运行?... – exception1

+1

循环从不启动,因为'时间'是-1。 'i'为'0',所以条件'我<时间'('0 <-1')不满足 –

+0

'if(ran = 0)'样式行非常可疑。 'ran = 0'正在赋值并且整数赋值给if中的'Random'。 –

回答

0

循环运行从iTime。但是,i = 0int Time = -1因此,循环将永远不会输入,因为'0 < -1会产生错误。

此外,if(ran = 0)这是不正确的,ran是一个Random类中的一个对象,你实例化它以获取随机数。随机数被保存到变量x和y。

+0

感谢您的时间修复。但问题仍然存在,代码仍然无法运行。我们遇到了运行错误 –

+0

您可以显示错误/进一步解释您的问题? – anaxin