i trying to write a code which will read from user input of the percentage of some words to be appear.
example
user will input 50 5 when the program runs. 50 is the total number of runs and 5 means of the total runs it will have 5% of maybe appear "detected".

i need on some advice of making the 5% that will appear "detected" out of the 50?

i trying to write a code which will read from user input of the percentage of some words to be appear.
example
user will input 50 5 when the program runs. 50 is the total number of runs and 5 means of the total runs it will have 5% of maybe appear "detected".

i need on some advice of making the 5% that will appear "detected" out of the 50?

You need to provide way more detail and use much more precise language. I can guess what you are trying to do, but it's just a guess.

it requires user to input 2 values. one of the values is the total number and the other value is percentage it will occur.
Example:
user enter --> 50 5
50 --> means the total number of runs
5 --> means 5% will occurs

i need on some advice on how to implement out of the total only 5% will print "detected"

it requires user to input 2 values. one of the values is the total number and the other value is percentage it will occur.
Example:
user enter --> 50 5
50 --> means the total number of runs
5 --> means 5% will occurs

i need on some advice on how to implement out of the total only 5% will print "detected"

????

I don't know about anyone else. Maybe it makes sense to them. I have no idea what this sentence means:

i need on some advice on how to implement out of the total only 5% will print "detected"

Also, where do these "words" that are being "detected" (I have no idea what "detected" means here) come from?

i word "detected" is just a hard coded string.

i need on some advice on how to implement out of the total only 5% will print "detected"

the above statement means i don know how to code it maybe someone can give me some hints on doing it

What is the total?

Are you saying that, you will have for example a loop running 50 times.
Sometimes the loop will print, some times it will not:

for (int i=0;i<50;i++) {

if (something) System.out.println("detected"); //5% of the times, this will be printed
else System.out.println(""); //nothing printed

}

Is this what you are trying to accomplish?

yes javaAddict!!! it is wat i meant but how can i make it that 5% it will print out "detected"?

This method returns numbers from 0 to 1: Math.random() In the for loop take a number between 0 and 1. (0% - 100%)
If the number is lower than the percentage print, else don't print.

0 ------ 5% (0.05) ------------------------------------- 100% (1.0)
|---------|---------------------------------------------------|
|
^
If the number is here (between that space) then print. If it is outside of that space don't print

Member Avatar for harsh2327

Well I have not understood your problem completely, but from what I have understood here's the solution

Step1. Take input to a string. Note: "50 5" will be bought in a single string
Step 2. Split the string w.r.t. " " (Space) using split function in String class.
Step 3. split() method returns array of string.
Step 4. Apply Integer.parseInt() method on second string obtained after splitting

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.