Finding a certain random value in which row and how many times has been appeared
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
KALYAN ACHARJYA
am 3 Jan. 2023
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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!