如何修改程序并使用arraylist

如何修改程序并使用arraylist

本文介绍了如何修改程序并使用arraylist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import java.util.Scanner;

public class Unique
{
// gets 5 unique numbers from the user
public static void main(String args[]) {
{
Scanner input = new Scanner( System.in );

/* Create an array of five elements*/ 
int count = 0; // number of uniques read
int entered = 0; // number of entered numbers

while( entered < numbers.length )
{
System.out.print( "Enter number: " );
/* Write code here to retrieve the input from the user */

// validate the input
/* Write an if statement that validates the input */ 
{
// flags whether this number already exists
boolean containsNumber = false;

// increment number of entered numbers
entered++;

/* Compare the user input to the unique numbers in the array using a for 
statement. If the number is unique, store new number */

/* add the user input to the array only if the number is not already 
in the array */
if ( !containsNumber )
{
/* Write code to add the number to the array and increment 
unique items input */
} // end if
else 
System.out.printf( "%d has already been entered\n",
number );
} // end if
else
System.out.println( "number must be between 10 and 100" );

// print the list of unique values
/* Write code to output the contents of the array */
} // end while 
} // end method Main
} // end class Unique













我尝试过的事情:



推荐答案


这篇关于如何修改程序并使用arraylist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 16:43