السلاااام عليكم ورحمه الله وبركااته
عندي هووم ورك اليووم لازم يتسسلم ومو فااهمه السؤال اللي مرتبط بيه
وهذا السؤؤال
كود PHP:
Use a one-dimensional array to solve the following problem: Write an application that inputs five numbers, eachof which is between 10 and 100, inclusive. As each number is read, display it only if it is not a duplicate of a numberalready read. Provide for the “worst case,” in which all five numbers are different. Use the smallest possiblearray to solve this problem. Display the complete set of unique values input after the user inputs each new value.
وهذا حلوو بس موو كامل
كود PHP:
1 // Lab 1: Unique.java
2 // Reads in 5 unique numbers.
3 import java.util.Scanner;
4
5 public classUniqueTest
6{
7 public static void main( String args[] )
8{
9 getNumbers();
11} // end main
12
13// gets 5 unique numbers from the user
14public void getNumbers()
15 {
16Scanner input = new Scanner( System.in );
17
18/* Create an array of five elements*/
19int count = 0; // number of uniques read
20int entered = 0; // number of entered numbers
21
22while( entered < numbers.length )
23{
24 System.out.print("Enter number: " );
25 /* Write code here to retrieve the input from the user */
26
27 // validate the input
28 /* Write an if statement that validates the input */
29 {
30 // flags whether this number already exists
31 booleancontainsNumber = false;
32
33 // increment number of entered numbers
34 entered++;
35
36/* Compare the user input to the unique numbers in the array using a for
37statement. If the number is unique, store new number */
38
39/* add the user input to the array only if the number is not already
40in the array */
41if ( !containsNumber )
42{
43/* Write code to add the number to the array and increment
44unique items input */
45}// end if
46else
47System.out.printf("%d has already been entered\n",
48number );
49}// end if
50else
51System.out.println("number must be between 10 and 100" );
52
53// print the list of unique values
54/* Write code to output the contents of the array */
55}// end while
56}// end method getNumbers
57}// end class UniqueTest
وهذا الاوت بووووت
كود PHP:
Enter number: 11
11
Enter number: 85
11 85
Enter number: 26
11 85 26
Enter number: 11
11 has already been entered
11 85 26
Enter number: 41
11 85 26 41
ي ليت تفيدووني كل سطر وش نسسوي فيه
ما أبغاا كوود
دمتم بوووووووووود