yeah i noticed that too
1 Like
Interesting topic.
I learned all about Double.POSITIVE_INFINITY!
https://stackoverflow.com/ has some good discussions about:
Double.POSITIVE_INFINITY
It is important to know the sizes of data types.
References for the sizes of primitive data types:
- https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
- https://www.baeldung.com/java-primitives
An exercise I worked through:
println(2147483647);
println(2147483647+1); //Take a good look at the integer output for this!
//println(2147483648); See the warning for this!
//Warning in console:
//The type *int* can't handle numbers that big. Try 2147483648L to upgrade to long.
println(2147483648L);
println();
int xInt = 2147483647;
println(xInt);
println(xInt+1);
println();
long xLong1 = 2147483647 + 1;
//println(xLong1);
System.out.println(xLong1);
println();
long xLong2 = 2147483647L + 1L;
//println(xLong2);
System.out.println(xLong2);
println();
for(int i = 2147483647-3; i>0; i++)
{
println(i);
}
println();
for(int i = 2147483647-3; i<214748368L; i++)
{
println(i);
}
println();
for(int i = 2147483647-3; i<2147483647; i++)
{
println(i);
}
println();
//An infinite loop - uncomment this if you want to run it:
//for(int i = 2147483647-3; i<=2147483647; i++)
// {
// println(i);
// }
//println();
// An infinite loop - uncomment this if you want to run it:
//for(int i = 2147483647-10; i<2147483648L; i++)
// println(i);
:)
why is this not working?
int x=19999;
int i=0;
void draw(){
if (i==0){
print(0.);}
for( i=0; i<x; i++){
if (i==x){
print(1);
stop();}}}
Just for fun, but not for the sake of efficiency, can you do it without a for
or while
loop?
Try this, and think about how it works:
void setup() {
print_char_x_times('a', 20);
}
void print_char_x_times(char ch, int times) {
if (times > 0) {
print(ch);
// recursive function call
print_char_x_times(ch, times - 1);
}
}
1 Like
Please use ctrl-t in processing prior to posting
It doesn’t work because for loop stops 1 before x and x is never reached
Hello,
It is good to develop the skills to seek out resources and examine your own code.
Example:
int x=19999;
int i=0;
void setup()
{
println("a", i, x);
for(i=19990; i<x; i++)
{
println("b", i, x);
if (i==x)
{
print("c", i);
}
}
}
Reference:
:)