1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
devlian [24]
3 years ago
7

Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exac

tly one space (i.e., if a number appears multiple times, it is displayed only once).
(Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.)

After the input, the array contains the distinct numbers in the order of their input.
Computers and Technology
1 answer:
ELEN [110]3 years ago
6 0

Answer:

The program to this question can be given as:

Program:

//import package.

import java.util.*;

public class Main //defining the class

{

public static void main(String[] args) //defining main method  

{

 Scanner ob = new Scanner(System.in); //creating scanner class object.

 int[] a = new int[10];//define array.  

 int number,counts= 0,i;//define variable.

 System.out.print("Enter numbers: "); //message.

 for (i = 0; i < 10; i++) //loop  

 {

  number=ob.nextInt();

  if (isDistinct(a,number))

  {

      a[counts] = number;//assign value in array

      counts++; // Increment count

  }

 }

 System.out.println("The distinct numbers is :" + counts);

 System.out.print("The distinct number are :");

 for (i = 0; i <a.length; i++)//loop

 {

  if (a[i] > 0)

  {

   System.out.print(" " +a[i]);//print array.    

  }

   

 }

 System.out.println();

}

public static boolean isDistinct(int[] array, int num)//defining method  

{

 for (int i = 0; i < array.length; i++)//loop for check number  

 {

  if (num == array[i]) //check condition

  {

      return false; //return value false.

  }

 }

 return true; //return value true

}

}

Output:

First time run:  

Enter ten numbers: 1 2 3 4 5 6 7 8 9 10

The number of distinct numbers is 10

The distinct numbers are 1 2 3 4 5 6 7 8 9 10

Second time run:

Enter numbers: 2 3 5 8 7 4 3 2 1 2

The distinct numbers is :7

The distinct number are : 2 3 5 8 7 4 1

Explanation:

The description of the above java code can be given as:

  • In the above java code, a class is defined that is main inside a class-main function is defined in the main function firstly creating a scanner class object that is "ob" then define variables and array that are number, counts and a[].
  • To inserts array elements we use a loop. In the loop, we use integer variable number and define a condition in if block passes a function that check value count total value.
  • In the second loop, we check the condition that array elements value is greater than 0 and print all array elements.
  • The isDistinct function checks in the array two values are not the same. if the values are the same it will return false value because this function is the boolean type that returns an only boolean value.
You might be interested in
jelaskan tiga kemungkinan sebab pengasah pensil itu tidak dapat berfungsi secara tiba-tiba (translate: explain three possible re
boyakko [2]

Explanation:

Internal gear wear must be significant (visually obvious) to be the cause of off-center sharpening. Cutter carrier is rotating but the pencil is not sharpening (doesn't feel like the cutter is engaging the pencil) This is usually caused by a foreign object (e.g., an eraser or broken pencil lead) inside the pencil bore.

3 0
3 years ago
Your customer asks you if it would be worth the investment for him to have Ethernet cabling installed to reach each of his works
Helen [10]

Answer:

Yes

Explanation:

Depending on the ethernet standard used, the IEEE 802.3 is faster than the WIFI (IEEE 802.11ac).

The ethernet protocol on cabled networks are of different speed based on ethernet standard which ranges from 10 Mega-bits to 100 Giga-bits per second. This protocol is found in the physical layer of the OSI model.

The wifi 802.11ac also known as wifi 5 is a wireless connection medium in the physical layer of the OSI model. It has a range of aggregate speed capacity of  433 mega-bits per second to 6.77 giga-bits per second.

5 0
3 years ago
Write an algorithm to print the minimum and maximum of an integer array. Your need to pass the array as a parameter. Since we ca
sammy [17]

Answer:

See explaination

Explanation:

MinMax.java

import java.util.*;

public class MinMax

{

static void MinMax(int[] arr)

{

int Min=arr[0]; // initializinf min and max with 1st value of array

int Max=arr[0];

for(int i=0;i<arr.length;i++) // iterating loop only once

{

if(arr[i]>Max) // checking max value

{

Max=arr[i];

}

if(arr[i]<Min) // checking min value

{

Min=arr[i];

}

}

System.out.println("Min Number is "+Min); //printing min value

System.out.println("Max Number is "+Max); //printing max value

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter N value: "); // taking n value

int n=sc.nextInt();

int[] arr=new int[n];

System.out.println("Enter N elements:"); // taking n elements into array

for(int i=0;i<n;i++)

{

arr[i]=sc.nextInt(); // each element into the array

}

MinMax(arr); // calling MinMax() method.

}

}

4 0
3 years ago
In network security, a firewall is a device which lies between two networks.
AfilCa [17]
The answer is A. A firewall is a piece of software that monitors all connections to make sure no attacks can be made in the internal or external networks
4 0
3 years ago
Which task does Word NOT give you the ability to accomplish?
ale4655 [162]

Is this multiple choice?

4 0
2 years ago
Other questions:
  • Ted is a fashion designer. Where is he most likely to work
    9·1 answer
  • How can you logout your account and do not want to have this anymore
    12·2 answers
  • Your friend sends you a photograph of his son. you want to enlarge the photograph. which program type will you use to make this
    15·1 answer
  • Given that the time to read data off a 7200 rpm disk drive will be roughly 75% of a 5400 rpm disk, at what idle time of the 7200
    13·1 answer
  • Im being timed please help!!
    7·2 answers
  • In Python, arrays are usually reserved for
    12·1 answer
  • Free 35 points!!!
    11·2 answers
  • write code that removes the first and last elements from a list stored in a variable named my_list. assume that the list has bee
    13·1 answer
  • How does the technology affect you daily living? Give situations where you use technology and how it helped you.​
    14·1 answer
  • ______ is used to extract knowledge from sources of data-NoSQL databases, Hadoop data stores, and data warehouses-to provide dec
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!