MCQ Blog
Blog about my MCQ practice
Trystan
Java Takeaways
1. String.substring(int i, int k);
Turns out I forgot that the substring doesn’t include the index listed in k:
String myString = "AAAB";
// index: 0, value 'A'
// index: 1, value 'A'
// index: 2, value 'A'
// index: 3, value 'B'
//substring doesn't include index 3
System.out.println(myString.substring(0,3));
AAA
this means that substring(int i, int k) equivially follows the math domain [i,k)
2. Math.random();
“Returns: a pseudorandom double greater than or equal to 0.0 and less than 1.0.” (java docs)
//results in an infinte loop
while(true){
if(Math.random() == 1) //this will NEVER be true
break;
}
//btw don't run this, it won't stop
This is again following a similar domain [0,1)
3. OR operator (||) vs. AND operated (&&)
This one is self explanable, I was moving too fast and mixed the two up on a problem