Jump to content

About This Club

This club is for people who want to share anything related to Java & Android development!

  1. What's new in this club
  2. Its not. I joined this club so i could respond If you have a double or a float in any language, you can't expect them to be completely precise. For example, if you have two doubles double num1 = 3.0; double num2 = 3.0; It looks like they should be equal, right? But they most likely aren't. why? because floats and doubles are very precise. Here's what num1 and num2 really are: num1: 3.00000000000000000000000000000000382918 num2: 3.00000000000000000000000000000000261527 So that's why you can't compare doubles and floats with the == operator in any language really. Here's some code to correctly compare floats in c++ bool cmpf(float a, float b){ return (fabs(a - b) < 0.005f); } I guess in Java it would be something ridiculous like static boolean cmpf(double a, double b){ return (Math.abs(a - b) < 0.005); } I f***ing hate java
  3. Yes this is the right answer. Now tell us why (==) isn't efficient to compare double variables?
  4. Can you specify it?... I dont understand is it this? Double.compare(double1,double2) == 0);
  5. You can do double1.equals(double2) Never mind it's only for string
  6. Given two double values double1 , double2, why isn’t it reliable to test their equality using: double1 == double2; ??? Comment possible code below!! If you are the first person to get this I will follow you!! HINT:
  7. You could also put nested if's but those are more complex so I left them out. if{ else{ if } } if{}
  8. I mean you're showing if statements bases on one condition only so if{} else {} but you couls try putting If Else if Else if Else So they understand they can use multiple conditions
  9. Nice :) you should consider putting else if statements also ;)
  10. If & If-Else Statements An If Statement is a conditional statement. This basically means that if the program is allowed to execute a specific set of instructions, it will but, only if that condition is met. If that condition is not met the program skips over the instructions. An example of an If Statement is as followed: public class Test { public static void main(String args[]) { int x = 15; \\initialzes an integer (x) to 15 if( x < 20 ) { System.out.print("This is if statement"); \\this prints if x is less than 20 } } } An If-Else Statement works very similarly to an If Statement. The only major difference is that if your 'if' is NOT met it goes to 'else' and runs that code in the program. Instead of skipping over the conditional. An example of an If-Else Statement is as followed: public class Test { public static void main(String args[]) { int x = 30; \\like before, declares integer to a value. In this case 30 if( x < 20 ) { //if x is less than 20 (it is not) it will run the if-clause System.out.print("This is if statement"); } else{ // if the x is greater than 20 (in this situation) it runs the else-clause System.out.print("This is else statement"); } } } Some very common errors in If and If-Else Statements could be the following: if (yourCondition); \\<< IF YOU PUT A SEMICOLON HERE IT ENDS THE STATEMENT WITHOUT READING THE ACTUAL STATEMENT { //code here } That code will result in an error! -LifeElevated
  11. This topic was moved from Topics to Java & Android development Tutorials.
  12. Nice man Like the other comments said, you should elaborate on certain aspects but this is nice to begin with
  13. Could you explain what each line does please? I might get into it.
  14. Nice TuT But since it's for complete beginners I suggest you explain the code more (I.E. Public vs Private classes. The fact it uses dot notation) Other than that it's pretty good
  15. Basic Java Program (first program) SCROLL DOWN TO BOTTOM FOR LINE BY LINE EXPLANATION This tutorial is for people who have never programmed in their lives. What you will need: A Compiler (For fun programs I use Eclipse java IDE for Developers) 1) You will first need to create your project and a class (using the traditional camelCase) 2) Create the following methods: 3) Compare your code to this: 4) Experiment with the simple System.out.print(""); putting "println" instead of just "print" "ln" will compile and after the text is printed it will go to the next line. 5) Print "Hello World!" To print text all you have to do is place text inside of the "" for example: as you can see above when ran it my text inputted! 6) That's it for a cool example of one of my old projects experimenting with printing copy and paste this code into your compiler! FEEL FREE TO EDIT AND PLAY AROUND WITH THIS CODE* https://raw.githubusercontent.com/TorinTurner/java/master/Corvette *do not take credit for my code. Also, the program is an example of polymorphism and/or inheritance. Line by Line Explanation: public class helloWorldEXPLAINED { //public means that this class is accessable by other packages, private means it is NOT accessable by other packages public static void main(String[] args) { //public and static means that it can be changes throughout the class // TODO Auto-generated method stub System.out.println("Hello World"); //this is your basic. System accesses the system lol, out means output, and print means print to console or whatver you initailzed to } } -LifeElevated
  16.  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.