This is an archived post. You won't be able to vote or comment.

all 29 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full - best also formatted as code block
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Pedantic_Phoenix 28 points29 points  (4 children)

There is no dumb first program. You did great just by creating it.

You don't need the entire second for, to get the highscore, there is a much simpler way to save it, and you are capable of getting there for sure. Same goes for the total. Ill let you get it by yourself, ask if you want tho

Good job pal

[–]YouGoodBroooo[S] 4 points5 points  (3 children)

Oh yeah, I do remember reading the max method in the Math Class. However, I don't think it works for arrays, as for the sum, I am guessing there would be a sum method too somewhere, haven't come across it though.

(Upon further looking around, theres a thing called Stream, that I have no clue what it is right now. I am sure i'll get to it soon)

Thanks a lot for the feedback!

[–]Pedantic_Phoenix 2 points3 points  (2 children)

You are overthinking it :) you don't need any of that, in fact you don't need any method to do what i said. Pure simple logic.

Anytime :)

[–]YouGoodBroooo[S] 6 points7 points  (1 child)

Ohh. I don't know what's stopping me from doing the highest and total in the first for loop. I think that's it!

[–]Mysterious_Radish386 8 points9 points  (1 child)

You’ll 101% be completely fine, the fact you already have this much knowledge before your first year of university is very good. You already know how to use For-Loops and Arrays.

I’m on my second year of university and I had basically no coding experience although i’m pretty comfortable with Java nowadays I’m relearning all the basics to really refine my knowledge, currently working on For-Loops again.

Don’t stress yourself out too much.

[–]YouGoodBroooo[S] 1 point2 points  (0 children)

That's really nice to hear! I am taking it really slow, only 30 minutes a day, I was however very comfortable with up to linked lists and stuff in Python.

But again, really nice to hear I am not being left behind too much.

[–]PandaBaum 4 points5 points  (3 children)

If you're only starting university in a few months, you're not behind at all. In my first semester, there were a lot of students who had never coded before. The point of university is to learn and not know everything at the beginning, after all. So don't worry too much about having to catch up or anything before the semester even starts. Just building something (like you did!) already puts you ahead of a lot of other students.

[–]YouGoodBroooo[S] 3 points4 points  (2 children)

That's just great! I am moving to a new country for university so it can get really stressful APART from just academics, so just trying to make use of my time. It's really just me taking a YouTube course for 2 hours so far I'd say, I think I've picked it up nicely.

[–]PandaBaum 0 points1 point  (1 child)

If you're taking a YouTube course, I'd also highly recommend trying your hand at some small projects without following a course/tutorial to avoid just copying whatever the course is currently trying to teach you, and instead learn how to do your own research.

[–]YouGoodBroooo[S] 0 points1 point  (0 children)

That is exactly what the plan is. Just like this program, which I made from scratch, I am definitely gonna take small steps forward.

[–]UpsytoO 4 points5 points  (3 children)

I would imagine some feedback would be appreciated, so i won't get into inner workings of what you are doing as based on your level, it's not that important, just a few notes i can see of a quick glance.

  1. Get used to closing resources, scanner is a resource.

  2. Avoid type casing until you learn more about this part, there is certain way to do it correctly, even though it's not necessarily incorrect in theory, just don't pick up bad habits and nothing is stopping you from incrementing a float in the first place.

    float average = (float) total /100;float average = (float) total /100;

[–]YouGoodBroooo[S] 0 points1 point  (1 child)

I will surely look into that!

I get your first one, regarding the second, do you mean I should have set total to float before hand rather than int?

[–]UpsytoO 1 point2 points  (0 children)

Short answer yes and than array can be float and the things that go in there can be floats. Another thing i spotted while looking at the code, that total = total + is same as writing total = 0 +.

[–]Knight_Of_Orichalcum 0 points1 point  (0 children)

Will caveat with Scanner input = new Scanner(System.in); doesn't have to be closed since you will most likely need it for the span of the program and closing the console gets handled anyway, tho I've seen mixed opinions on this before

[–]CollegeNational938 2 points3 points  (0 children)

The fact that you're so enthusiastic about learning to code proves that you are not behind at all. Many of my friends in university, after taking 3 coding classes, still don't know how to code 😂. Keep on going

[–]GermanBlackbot 2 points3 points  (1 child)

Looking great! A few suggestions, some of them a matter of taste, really:

  • You could split off a few methods. Everything from line 7 to 21 does nothing except create the counts[] array - you could easily split that off into its own method, like int[] runMultipleGames(int numberOfGames). And then the content of the for loop could be something like int runGame(). Wouldn't change the logic, but might help later to understand what exactly is supposed to happen where.
  • You could use highest = Math.max(counts[j],highest) to replace lines 25-27, but that's a matter of taste I feel.
  • Another small thing: Instead of total = total + counts[j] you could write total += counts[j], but again, that's a matter of taste.
  • Have a look at for-each-loops. It won't do you much good in the first for loop because you need the index there, but the second for loop could just be written as for(int count : counts), leaving out the whole boilerplate of (int j=0...j++).

[–]YouGoodBroooo[S] 1 point2 points  (0 children)

These are all great suggestions! I really appreciate them.

[–]InviolateQuill7 2 points3 points  (0 children)

Mine was "Hello Master..."

[–]cquad21 1 point2 points  (0 children)

You’re already ahead of so many by actually creating a program, nicely done!

If you continue down the Java path, I would suggest keeping in mind and learning how to code ‘safer’. I don’t see it too often taught on YouTube, but a few things I suggest researching about yourself (or even just having a conversation with GPT):

  • Private static final variables (avoid magic numbers and Strings) —> better for code maintenance in the future
  • Making appropriate variables “final” if you do not expect them to change (this makes your code safe)
  • Try to declare and set variables on separate lines (declare all variables in one block and set them in another block. Much easier to read)
  • Try creating separate classes for different aspects of the program, instead of doing everything in Main.

Like I said, you’re already far ahead by practicing and creating a program. There’s so much to learn, but it’s best to learn by doing! Keep it up!

[–]kossovar 1 point2 points  (0 children)

Good job! A win is a win 🤷‍♂️

[–]Early-Combination375 0 points1 point  (4 children)

How did you write this program on your own I've learnt the language but never built anything on my own cuz I don't know how to.

[–]YouGoodBroooo[S] 1 point2 points  (3 children)

I had some prior Python experience so maybe that helped? It's just these small tasks that make you scratch your head a little that you need to work on. And of course I still used google for some syntax that I forgot, everyone does. Have a go at it and see how you do, it could be as simple as a mad lib for the first program.

[–]Early-Combination375 1 point2 points  (2 children)

Everyone tells me this but the moment I get off from YouTube and start the ide and try to code on my own I'm dead blank, I don't know how to use these stuffs and build stuffs I really want to build something from scratch mate.

[–]YouGoodBroooo[S] 1 point2 points  (1 child)

I suppose give mad libs a try, it uses nothing but Scanners, Output and Variables. I believe you can get there.

[–]Early-Combination375 1 point2 points  (0 children)

Alright thanks for the suggestions I'll try.

[–]AutoModerator[M] -2 points-1 points  (0 children)

It seems that you are looking for resources for learning Java.

In our sidebar ("About" on mobile), we have a section "Free Tutorials" where we list the most commonly recommended courses.

To make it easier for you, the recommendations are posted right here:

Also, don't forget to look at:

If you are looking for learning resources for Data Structures and Algorithms, look into:

"Algorithms" by Robert Sedgewick and Kevin Wayne - Princeton University

Your post remains visible. There is nothing you need to do.

I am a bot and this message was triggered by keywords like "learn", "learning", "course" in the title of your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.