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
Which library research databases include information about articles published in magazines, journals, and newspapers? question 1
Alecsey [184]

Answer:

periodical databases

Explanation:

Among the various databases you can now access in a library, the periodical databases contains the text and other information about articles published in magazines, journal and newspapers.

This database allows you for example to easily search for all articles written about a specific event or person, and it will return you the list of articles you can then read from a single spot, no matter where or when the article was written.

8 0
3 years ago
What is the main difference between a literacy society and a digital Society
EleoNora [17]
The accurate answer is

The difference is a Literacy Society is a program for encouraging people to read.
A Digital Society is a program that as to do with technology at work,school, or at home.

Glad to help :) 
7 0
3 years ago
To decrease the size of text so it will fit into a text box without overflowing, select the
Trava [24]

Answer:

It is is A

Explanation:

Becuase if you shrink a text thats just the answer

5 0
3 years ago
Read 2 more answers
The application layer in the tcp/ip protocol suite is usually considered to be the combination of ________ layers in the osi mod
navik [9.2K]
Application Presentation and Session Layers.
8 0
3 years ago
Where does the CPU store its computations
mario62 [17]

Answer:

In main memory

Explanation:

Hope this helps

8 0
3 years ago
Read 2 more answers
Other questions:
  • Navigational signs on the highway are often which colors?
    10·2 answers
  • To make sure that you do not get too tired when typing for long periods, how often should you get up and stretch? Every 15 minut
    9·1 answer
  • Plagiarism occurs when writers
    14·2 answers
  • In the structure of a conventional processor, what is the purpose of the data path?
    15·1 answer
  • Which of the following is not true about designing classes? In order for class information to be printed instead of a memory add
    12·1 answer
  • 1.) what is the minimum number of bits required to represent -3,997 using 2's complement form?
    6·1 answer
  • You have a web application hosted in AWS cloud where the application logs are sent to Amazon CloudWatch. Lately, the web applica
    7·1 answer
  • . An access specifier is one of three keywords:
    14·1 answer
  • True or false.local and cloud backup differs in where the backup is saved
    15·2 answers
  • Find the name of the professor with the maximum percentage of students that failed his course.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!