Java Array Common Error

Introduction

Identify and fix the errors in the following code:


public class Main {
  public static void main(String[] args) { 
     double[100] r; 
        
     for (int i = 0; i < r.length(); i++); 
         r(i) = Math.random * 100; 
  }
}


public class Main {
  public static void main(String[] args) { 

     double[100] r; //should be double[] r = new double[100]; 

                           //no ()         
     for (int i = 0; i < r.length(); i++); // no ;
         r(i) = Math.random * 100; 
       //r[i]       missing() 
  }
}
public class Main {
  public static void main(String[] args) { 

     double[] r = new double[100]; 

        //from  ww  w  . j  a  v a2 s . c  o m
     for (int i = 0; i < r.length; i++)
         r[i] = Math.random() * 100; 
  }
}



PreviousNext

Related