Author Topic: java anyone?  (Read 23008 times)

0 Members and 1 Guest are viewing this topic.

Offline RebelFreedom

  • SA-MP Donator
  • *
  • Posts: 130
  • IM NOT RACIST, I HATE EVERYONE EQUALLY
    • Awards
  • SA-MP: RebelFreedom
Re: java anyone?
« Reply #30 on: March 11, 2013, 07:10:28 PM »
im learning code as well ;) i can change it any wich way i wish usually, but i cant ever write it all from scratch.. i also gotta self teach myself.. any tips for me as well would be much appreciated! awesome! any websites and book names would be good too ;) ima learn C++ and java.. currently reading up on java.. is that bad? i hear u guys dont like it. lol
"People who get 'offended' offend me." - RebelFreedom

Offline SKY

  • Quad Buddy
  • SA-MP Retirees
  • *
  • *
  • Posts: 842
  • GrandDaddy Bikerr, LETS GET IT LETS GO!
    • Awards
Re: java anyone?
« Reply #31 on: September 21, 2014, 02:50:17 AM »
Anyone started to use java recently? Im beginning to learn it at my computer science class.  ;D
Since 2008
If you are not part of the quadbuddy association than we can not be friends.

Offline EnzoMortelli

Re: java anyone?
« Reply #32 on: September 21, 2014, 10:10:25 AM »
http://imgur.com/gallery/o3I3R i found this very useful.

Offline SKY

  • Quad Buddy
  • SA-MP Retirees
  • *
  • *
  • Posts: 842
  • GrandDaddy Bikerr, LETS GET IT LETS GO!
    • Awards
Re: java anyone?
« Reply #33 on: November 05, 2014, 04:49:25 AM »
Hi guy's for my computer science class I been practicing using the string class, I created a method to create three random letter where the first and last are consonants and the middle is a vowel. The method tries to create the word cat. Here is my code http://pastebin.com/VFC1J53T if anyone know's a simpler way to do this please let me know. Also can someone explain why for  k = r.nextInt(21) + 1; , were r is a random object to create a random integer between 1 and 21, I had to add 1? :)
« Last Edit: November 05, 2014, 04:51:02 AM by SKY »
Since 2008
If you are not part of the quadbuddy association than we can not be friends.

Offline EnzoMortelli

Re: java anyone?
« Reply #34 on: November 05, 2014, 09:37:59 AM »
Code: [Select]
return word;
word = firstWord + secondWord + thirdWord;
System.out.println(word);
the two bottom lines are unreachable code. Return obviously returns from the method to the main program, thus ends the execution flow of the method before your word is set, your return should be NULL. Have you tried this method even once? ???
(Also Eclipse should mark unreachable code)

Simpler way:

Code: [Select]
public static String createWord() {
          String word = "cat";
          return word;
}

r is a random object that is used for random real values between 0 and 1. The method nextInt(int n) returns a pseudorandom integer number between 0 (inclusive) and n (exclusive) on a random object.
Thus r.nextInt(21) gives a random int between 0 and 20, adding +1 shifts the range from 1 to 21.

Code: [Select]
while(true){My laptop overheats just by seeing this.
« Last Edit: November 05, 2014, 09:43:27 AM by EnzoMortelli »

Offline Fuse

  • SA-MP Donator
  • *
  • Posts: 1048
    • Awards
Re: java anyone?
« Reply #35 on: November 05, 2014, 10:09:51 AM »
I made my own version of your code in pawn.
Check it out and you might learn a thing or two, if you're lucky.

http://pastebin.com/wxZfZU9f

As enzo said above though, there are easier ways to do this, but i guess it's for educational purposes.

Offline Quickplay

  • SA-MP Retirees
  • *
  • *
  • Posts: 2212
  • Crazy Mind
    • Awards
  • SA-MP: Quickplay
Re: java anyone?
« Reply #36 on: November 05, 2014, 11:03:44 AM »
I made my own version of your code in pawn.
Check it out and you might learn a thing or two, if you're lucky.
Lol not even my professors are so "modest", and they are genius  ;D

Btw i don't know how much it could help him since it's another programming language

Code: [Select]
while(true){My laptop overheats just by seeing this.
lmao

Offline Fuse

  • SA-MP Donator
  • *
  • Posts: 1048
    • Awards
Re: java anyone?
« Reply #37 on: November 05, 2014, 12:56:14 PM »
Lol not even my professors are so "modest", and they are genius  ;D
what exactly are you implying here? lol

Offline SKY

  • Quad Buddy
  • SA-MP Retirees
  • *
  • *
  • Posts: 842
  • GrandDaddy Bikerr, LETS GET IT LETS GO!
    • Awards
Re: java anyone?
« Reply #38 on: November 05, 2014, 03:07:18 PM »
Thank's Fuse and Enzo for the help, also I noticed i pasted the wrong code but its the same thing but without the error after the return. http://pastebin.com/jBB61mfr
Since 2008
If you are not part of the quadbuddy association than we can not be friends.