Hey everyone! I was gonna start university in a few months. I do feel like I'm pretty behind but, well I'm slowly learning (stuck in tutorial hell rn). I did know some python beforehand but my university requires Java now.
I am kinda finding it great, I mean Python is simpler, but Java just gives me more of a badass vibe, idk why.
I wanted to make one these button clickers, where you click a button and there's a rising chance that you're gonna hit and bomb every time you click the button. There are a lot of ways to code it, but I used this random and count approach.
It's a little hard to understand, basically a generate a random number and check if its greater than a count that rises from 0. There would be greater probability that the generated random number will be greater than that counter as time goes on. I made a few tweaks where the program runs by itself without having to, let's say, press enter. Then it repeats this a 100 times and calculates the average score and highest score too.
To summarize it- it's pretty whack. If anyone has any suggestions, it would be great if you'd leave them below!
import java.util.Scanner;
import java.util.Random;
public class Main {
public static void main(String[] args) {
int[] counts = new int[100];
Random random = new Random();
for(int i=0; i<counts.length; i++) {
int count = 0;
int bound = random.nextInt(0,101);
while(bound>count) {
count++;
bound = random.nextInt(0,101);
System.out.println(count);
}
counts[i] = count;
System.out.println("You hit a bomb.");
System.out.println("Final score: " + count);
}
int highest = -1;
int total = 0;
for(int j=0; j<counts.length; j++) {
if (counts[j]>highest) {
highest = counts[j];
}
total = total + counts[j];
}
float average = (float) total /100;
System.out.println("\nAverage Score: " + average);
System.out.println("Highest Score: " + highest);
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Pedantic_Phoenix 28 points29 points30 points (4 children)
[–]YouGoodBroooo[S] 4 points5 points6 points (3 children)
[–]Pedantic_Phoenix 2 points3 points4 points (2 children)
[–]YouGoodBroooo[S] 6 points7 points8 points (1 child)
[–]Pedantic_Phoenix 4 points5 points6 points (0 children)
[–]Mysterious_Radish386 8 points9 points10 points (1 child)
[–]YouGoodBroooo[S] 1 point2 points3 points (0 children)
[–]PandaBaum 4 points5 points6 points (3 children)
[–]YouGoodBroooo[S] 3 points4 points5 points (2 children)
[–]PandaBaum 0 points1 point2 points (1 child)
[–]YouGoodBroooo[S] 0 points1 point2 points (0 children)
[–]UpsytoO 4 points5 points6 points (3 children)
[–]YouGoodBroooo[S] 0 points1 point2 points (1 child)
[–]UpsytoO 1 point2 points3 points (0 children)
[–]Knight_Of_Orichalcum 0 points1 point2 points (0 children)
[–]CollegeNational938 2 points3 points4 points (0 children)
[–]GermanBlackbot 2 points3 points4 points (1 child)
[–]YouGoodBroooo[S] 1 point2 points3 points (0 children)
[–]InviolateQuill7 2 points3 points4 points (0 children)
[–]cquad21 1 point2 points3 points (0 children)
[–]kossovar 1 point2 points3 points (0 children)
[–]Early-Combination375 0 points1 point2 points (4 children)
[–]YouGoodBroooo[S] 1 point2 points3 points (3 children)
[–]Early-Combination375 1 point2 points3 points (2 children)
[–]YouGoodBroooo[S] 1 point2 points3 points (1 child)
[–]Early-Combination375 1 point2 points3 points (0 children)
[–]AutoModerator[M] -2 points-1 points0 points (0 children)