Effacer les filtres
Effacer les filtres

Finding a certain random value in which row and how many times has been appeared

1 vue (au cours des 30 derniers jours)
N/A le 3 Jan 2023
Rouvert : N/A le 3 Jan 2023
Hello there we have a semester exercise in java and i would like a help, we want a program that stores a table of 20 random integer values and then asks the user to give a value from 0 to 20 and then to show if that value is among them how many times has appeared and in which positions
import java.io.*;
import java.util.Random;
class anazitisi // research
public static void main(String[]args) throws IOException
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader Input = new BufferedReader(reader);
int[] x = new int[20];
Random rndm = new Random();
int i= rndm.nextInt();
for( i=0; i<20; i++)
x[i] = rndm.nextInt(20);
for( i=0; i<20; i++)
System.out.println("Δώσε έναν αριθμό απο το 1 μέχρι το 20"); // give a value from 1 until 20
String AR1 = Input.readLine();
int b = Integer.parseInt(AR1);
System.out.println("O αριθμός" +x.length+ "βρέθηκε φορές στις θέσεις "); // the number....has been found x time in the positions.....
it's in greek but i hope you get the gist somehow any help please until 10/1 would be welcome i know it's very limited time ...Thanks in advance

Réponses (1)

This is a Matlab forum, Matlab answer, try to replicate in other langauges-
rand_data=randi([0 20],[1, 20])
num=input('Enter any number (0 to 20): ')
[r c]=find(rand_data==num)


En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by