Question

In: Computer Science

Write a Java program that takes an array of 10 "Int" values from the user and...

Write a Java program that takes an array of 10 "Int" values from the user and determines if all the values
are distinct or not. Return TRUE if all the values of the array are distinct and FALSE if otherwise.

Solutions

Expert Solution

input code:

output 1:

output 2:

code:

import java.util.*;
import java.io.*;
class Main {
/*make method for check distinct or not*/
static boolean Check(int input[])
{
/*check all element one by one*/
for (int i = 0; i < 10; i++)
{
/*check it is came ot not*/
int j;
for (j = 0; j < i; j++)
{
/*if came than return false*/
if (input[i] == input[j])
{
return false;
}
}
}
/*else return true*/
return true;
}
  
// Driver program
public static void main (String[] args)
{
/*declare the variables*/
int input[] = new int[10];
Scanner sc=new Scanner(System.in);
/*take input from user*/
System.out.print("Enter the values:");
for(int i=0;i<10;i++)
{
input[i]=sc.nextInt();
}
/*call function*/
boolean output=Check(input);
/*print outputs*/
if(output)
{
System.out.print("values are distinct.");
}
else
{
System.out.print("values are not distinct.");
}
}
}


Related Solutions

Write a Java program to randomly create an array of 50 double values. Prompt the user...
Write a Java program to randomly create an array of 50 double values. Prompt the user to enter an index and prints the corresponding array value. Include exception handling that prevents the program from terminating if an out of range index is entered by the user. (HINT: The exception thrown will be ArrayIndexOutOfBounds) *Please do it in eclipse and this is java language*
Q1-      Write a program that takes a list of values as an input from the user....
Q1-      Write a program that takes a list of values as an input from the user. The program should further ask the user about sorting the list in ascending or descending order. It is desirable to use Arraylist/Vector in place of simple arrays. (Object Oriented Programming java)
IN C++ Write a program that reads in int values from the user until they enter...
IN C++ Write a program that reads in int values from the user until they enter a negative number like -1. Once the user has finished entering numbers, print out the highest value they’ve entered, the lowest value they’ve entered, and the total number of numbers they’ve entered. The negative number they entered should not be taken as one of the values entered.
Write a java method that takes a string and returns an array of int that contains...
Write a java method that takes a string and returns an array of int that contains the corresponding alphabetic order of each letter in the received string: An illustration: the method takes: "Sara" the method returns: {4,1,3,2} another illustration: the method takes: "hey" the method returns: {2,1,3}
write a program that takes two input values from the user and calculate the division if...
write a program that takes two input values from the user and calculate the division if the first number is greater than the second one otherwise calculate the multiplication.
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
write a java program that takes three numbers from the user and print the greatest number...
write a java program that takes three numbers from the user and print the greatest number (using if-statement). sample output: input the first number:35 input the second number:28 input the third number:87 the greatest number:87
JAVA PROGRAM Write program that will prompt user generate two random integers with values from 1...
JAVA PROGRAM Write program that will prompt user generate two random integers with values from 1 to 10 then subtract the second integer from the first integer. Note, if the second integer is greater than the first integer, swap the two integers before making the subtraction.Then prompt user for the answer after the subtraction. If the answer is correct, display “Correct”otherwise display “Wrong”.You will need to do this in a loop FIVE times and keep a count of how many...
***Using Java Using the switch/case construct, write a program that takes a character from the user...
***Using Java Using the switch/case construct, write a program that takes a character from the user and classifies it as a number (‘1’,’2’, ‘3’, …), a letter from the alphabet (‘A’, ‘a’, ‘B’, ‘b’, …, ‘Z’, ‘z’), an arithmetic operator (‘+’, ‘-‘, ‘/’, ‘*’, ‘%’), a comparison operator (‘<’, ‘>’, ‘=’), punctuation (‘!’, ‘?’, ‘,’, ‘,’, ‘:’, ‘;’), and all other characters as a Special Character, and informs the user of the same. If the user entered the character A,...
Write a Java program that prompts the user to enter a list of integer values and...
Write a Java program that prompts the user to enter a list of integer values and displays whether the list is sorted in increasing order or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. <Output> Enter list: 8 101516619111 The list is not sorted <End Output <Output> Enter list: 10 11344579 11 21 The list is already sorted <End Output Create a complete class for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT