Hello,
I am currently playing with loops and am stumped on something. I am inputting x amount of values assigned to a random number. For every 5 values, i want to increment a value +1;
Example (setting number to 7):
Value 0, -23, 1
Value 1, -25, 1
Value 2, 50, 1
Value 3, 13, 1
Value 4, 08, 1
Value 5, 10, 2
Value 6, -82, 2
Here's what I currently have:
move to Java category if possible mods
I am currently playing with loops and am stumped on something. I am inputting x amount of values assigned to a random number. For every 5 values, i want to increment a value +1;
Example (setting number to 7):
Value 0, -23, 1
Value 1, -25, 1
Value 2, 50, 1
Value 3, 13, 1
Value 4, 08, 1
Value 5, 10, 2
Value 6, -82, 2
Here's what I currently have:
import java.util.Scanner; // Scanner
import java.util.Random; // Random
public class sup
{
private static Scanner scanner = new Scanner( System.in );
public static void main ( String[] args )
{
System.out.print( "Input number of values in the array: " );
String input = scanner.nextLine();
int number = Integer.parseInt( input );
int array[] = new int[number];
Random generator = new Random( 3 );
for(int x = 0; x < number; x = x + 1)
{
for(int y = x; y < 5; y=y+1) //I know I'm doing something wrong here
{
if(y ==4)
{
System.out.println(y);
}
}
int r = generator.nextInt();
array[x] = r;
System.out.println( "Index: " + x + " Value: " + r );
}
}
}
move to Java category if possible mods