Click here to Skip to main content
16,022,234 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
import java.utils.Scanner
public class lab  {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);

   int[0]userNum = scnr.NextInt();
   number_of_elements = 3;   //number of elements in array
   userNum[0] = 0;

   minVal =  ; 
for (i = 0; i < myVals.length; ++i) {
   if (myVals[i] < minVal) {
      minVal = myVals[i];
   }
}


What I have tried:

I've tried to alter the code various ways with continuous scanner errors
Posted

1 solution

You are trying to refer to variables that have not been defined, or defined incorrectly.
Java
int[0]userNum = scnr.NextInt();

You cannot declare an array with zero components. Change your code to something like:
Java
int count = scnr.NextInt(); // get the number of variables to process
int[] myVals = new int[count]; // create an array to hold the individual values
for (int i = 0; i < count; i++) {
//
// add code here to read the values you wish to process
// into the individual cells of the "myVals" array.
//
}
//
// add another loop here to find the minimum value
//
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900