Author Topic: java anyone?  (Read 6495 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 username: 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: 837
  • GrandDaddy Bikerr, LETS GET IT LETS GO!
  • Awards Littlewhitey's SA-MP Player of the Year 2014
    • 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
myprotein (dot) com whey code if you want a discount -> JOANNA-RM4
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: 837
  • GrandDaddy Bikerr, LETS GET IT LETS GO!
  • Awards Littlewhitey's SA-MP Player of the Year 2014
    • 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 »
myprotein (dot) com whey code if you want a discount -> JOANNA-RM4
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: 1047
    • 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: 2144
  • Crazy Mind
    • Awards
  • SA-MP username: 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: 1047
    • 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: 837
  • GrandDaddy Bikerr, LETS GET IT LETS GO!
  • Awards Littlewhitey's SA-MP Player of the Year 2014
    • 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
myprotein (dot) com whey code if you want a discount -> JOANNA-RM4
Since 2008
If you are not part of the quadbuddy association than we can not be friends.