Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Trying to figure out if you can make user input array then display it

$
0
0
Ok so I am wondering if it is possible to display an array that has its variable put in by the user. Its going to ask the user for a number, 10 times so there will be ten numbers in the array. How can you display the array now? I've tried doing print statement (number) and hasn't worked also print statement (index). Does anyone have any suggestions as they will be appreciated and helpful.

import java.util.Scanner;
public class LargestNumber {

	
	public static void main(String[] args) {
		Scanner scan = new Scanner (System.in);
		final int MAX = 10;
		int[] numbers = new int [MAX];
		int maxValue = numbers[0];
		
		for(int index = 0; index < MAX; index++){
			
			System.out.println("Enter a number" + (index+1) + ": ");
			numbers [index] = scan.nextInt();
		}
		System.out.println(numbers);
		
		//for (int i = 0; i < numbers.length; i++){
			//if (numbers [i] > maxValue){
				
			////	maxValue = numbers [i];
		//	}
			
		//}

		//System.out.println ("The largest number is: " + maxValue); 

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>