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 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}
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.
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...
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...
JAVA JAVA JAVA JAVA, My array has 1000 int variables with random values from 1-100, I...
JAVA JAVA JAVA JAVA, My array has 1000 int variables with random values from 1-100, I want to be able to scan and output which number appears the most and the least. int x =1000 int[] array = new array[x] for(int i = 0 ; i < x; i++){ array[i] = random.nextInt(101); }
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter...
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter and prints n stars (*) using for loop. ex. 6 ******
Write Java program Lab43.java which declares and initializes numeric array of 5 elements (int num[5]) and...
Write Java program Lab43.java which declares and initializes numeric array of 5 elements (int num[5]) and produces as output the sum of integers in an array, the largest and the smallest element in an array. Your program should contain the following methods: public static int sum(int[]) public static int findLargest(int[]) public static int findSmallest(int[])
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester. The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester.    The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
how to write a cpp program that takes a number from a user, and print the...
how to write a cpp program that takes a number from a user, and print the sum of all numbers from one to that number on screen? using loop interation as basic as possible.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT