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

조회 수: 2 (최근 30일)
N/A
N/A 2023년 1월 3일
다시 열림: N/A 2023년 1월 3일
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("x["+i+"]="+x[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

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2023년 1월 3일
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): ')
times_num=sum(rand_data==num)
[r c]=find(rand_data==num)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by