Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use a one-dimensional array to solve the following problem: Read in 10 numbers,

ID: 3714086 • Letter: U

Question

Use a one-dimensional array to solve the following problem: Read in 10 numbers, each of which is between 10 and 100. As each number is read, print it only if it's not a duplicate of a number that has already been read. Provide for the "worst case", in which all 10 numbers are different. Use the smallest possible array to solve this problem. This needs to be in Java and Html. I really haven't gone through the code to see what's wrong, I am a little behind with other things. Please help, I need it soon!

<!DOCTYPE html>

<html>

<head>

<title> Duplicate Number Array </title>

<script type="text/javascript">

public class Duplicate

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

int[] array = new int[10];

System.out.println("Please enter the numbers one by one below.");

// looping 10 times to input numbers one by one

for(int i = 0; i < array.length; i++)

{

int num = input.nextInt();

// if block to check whether number is unique or not

// if not duplicate then print the message

if(!isDuplicate(array, num, i))

System.out.println(num + " is not a duplicate number.");

array[i] = num;

}

}

/**

* Method to check whether a number exist in the array or not, passed as parameter

* @param array[]

* @param num to check

* @param size of array

* @return boolean

*/

public static boolean isDuplicate(int array[], int num, int size)

{

for(int i = 0; i < array.length; i++)

{

// checking whether num is equal to array[i]

// if yes then return true

if(num == array[i])

return true;

}

return false;

}

}

</head>

</html>

Explanation / Answer

We can use java script with html not java.... You are trying to use java between javascript tags. Below is your code in html and javascript.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>New Document</title>

<script type="text/javascript">

function writeNum()

{

var allNum = [];

var i = 0;

while (i < 20)

{

var curNum = prompt('Enter 20 ID number between 10 - 100!!!!', '');

if (!allNum['num' +curNum] && !isNaN(curNum) && curNum >= 10 && curNum <= 100)

{

document.write(curNum + '<br>');

allNum['num' +curNum] = true;

i++;

}

}

}

</script>

</head>

<body>

</body>

</html>