r/learnjava • • Jan 18 '23

Learning java at 44

I've decided to learn java so I'm doing a short free course on udacity. I'm quite enjoying but I got stuck on a very basic bit of code and need some help. I'm generating random numbers for dice but now need to change the number of sides from 6 to 8 using parameters. I gone over my notes but still not quite sure where I've gone wrong. This course doesn't give me the answer anywhere so I can't see where I've gone wrong. I know (int sides) are the parameters I have to use but not sure how. Some guidance please!!

Public int roll Dice (int sides){ randomNumber=Math.random(); randomNumber=randomNumber*6; randomNumber=randomNumber+1; int randomInt=(int)randomNumber;

return randomInt; }

43 Upvotes

18 comments sorted by

View all comments

2

u/[deleted] Jan 23 '23

This is not related to your problem as I see others have helped you, but a quick suggestion and guidance.

You should try to look up at https://www.javatpoint.com/ as there are many guides to what you need.

All java complete guide, data structures (usually written on C but it can be translated to java easily). Java programs and many interview java questions that companies usually ask + java programs for interview (algorithms, doubly linked lists and how to use nodes, tree search, sorting,etc.).

I suggest you learn everything from the beginning and go further but skip javaFX, java AWT / Swing because for the beginner this is not needed and almost no interviewer at companies will ask questions about it for the starting positions or junior. They most care about algorithms, data structures, Big O and such.

Another note is to download the book: ''Cracking the coding interview'' and start doing it when you get confident in your skills. The book holds many questions and possible problems that big companies use. Most answers are written in Java but if some are not, you can always download the solutions on their github page for any language desired.