Howdy. 

java.lang.Math is a class automatically imported. 

http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#random--

Range is [0, 1) uniformly distributed. 

I would to produce numbers in the range [a, b)

  (b - a) * Math.random() produces numbers in [0, (b - a))

After the stretch I also need to translate the interval 

  (b - a) * Math.random() + a produces numbers in [a, b) 

I only need integers so I cast 

  (int) ((b - a) * Math.random() + a) produces numbers in {a, a+1, ..., b-1} 

If a = 1 and b = 7 then the formula produces numbers in {1, 2, ..., 7-1}

  int dice = (int) (6 * Math.random() + 1); // simulates throw of dice

I want to prove to myself this works. 

Welcome to DrJava.  Working directory is C:\Users\dgerman
> Math.random()
0.42967538405120975
> Math.random()
0.6539674602138259
> Math.random()
0.8413375943167972
> Math.random()
0.9611533483324047
> Math.random()
0.15949480414692085
> Math.random()
0.7343929790583031


Welcome to DrJava.  Working directory is C:\Users\dgerman
> Math.random() * 6
2.3431309478801863
> Math.random() * 6
0.3335590387986431
> Math.random() * 6
4.938034269190595
> Math.random() * 6
4.207854582902165
> Math.random() * 6
4.182179180686965
> Math.random() * 6
0.22925920374561204


Welcome to DrJava.  Working directory is C:\Users\dgerman
> (int) (Math.random() * 6)
5
> (int) (Math.random() * 6)
2
> (int) (Math.random() * 6)
3
> (int) (Math.random() * 6)
2
> (int) (Math.random() * 6)
0


Welcome to DrJava.  Working directory is C:\Users\dgerman
> (int) (Math.random() * 6) + 1
1
> (int) (Math.random() * 6) + 1
1
> (int) (Math.random() * 6) + 1
4
> (int) (Math.random() * 6) + 1
2
> (int) (Math.random() * 6) + 1
3
> (int) (Math.random() * 6) + 1
3
> (int) (Math.random() * 6) + 1
2
> (int) (Math.random() * 6) + 1
6
> (int) (Math.random() * 6) + 1
1
> (int) (Math.random() * 6) + 1
6
> (int) (Math.random() * 6) + 1
1
> (int) (Math.random() * 6) + 1
4
> (int) (Math.random() * 6) + 1
4
> (int) (Math.random() * 6) + 1
3
> (int) (Math.random() * 6) + 1
4
> (int) (Math.random() * 6) + 1
2
> (int) (Math.random() * 6) + 1
3
> (int) (Math.random() * 6) + 1
1
> (int) (Math.random() * 6) + 1
3
> (int) (Math.random() * 6) + 1
4
> (int) (Math.random() * 6) + 1
2
> (int) (Math.random() * 6) + 1
3
> (int) (Math.random() * 6) + 1
3
> (int) (Math.random() * 6) + 1
5
> (int) (Math.random() * 6) + 1
2
>

public class Thursday {
  public static void main(String[] args) {
    int dice = (int) (Math.random() * 6) + 1;
    System.out.println( dice ); 
  }
}

public class Thursday {
  public static void main(String[] args) {
    int dice = (int) (Math.random() * 6) + 1;
    // System.out.println( dice ); 
    if (dice % 2 == 1) { // odd number 
      if (dice <= 3) { // 1 or 3
        System.out.println( dice + " is 1 or 3" ); 
      } else { // dice must be 5
        System.out.println( dice + " is 5" ); 
      }
    } else { // even number 
      System.out.println( dice + " is one of 2, 4, 6 " ); 
    }
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Thursday
6 is one of 2, 4, 6 


If a block has only one statement curly braces are not necessary. 

public class Thursday {
  public static void main(String[] args) {
    int dice = (int) (Math.random() * 6) + 1;
    // System.out.println( dice ); 
    if (dice % 2 == 1) 
      if (dice <= 3) 
        System.out.println( dice + " is 1 or 3" ); 
      else 
        System.out.println( dice + " is 5" ); 
    else 
      System.out.println( dice + " is one of 2, 4, 6 " ); 
  }
}

This works just the same. 

> (2 + (3 * 6))
20
> 2 + 3 * 6
20


Change the problem 

public class Thursday {
  public static void main(String[] args) {
    int dice = (int) (Math.random() * 6) + 1;
    // System.out.println( dice ); 
    if (dice % 2 == 1) { // odd number 
      if (dice <= 3) { // 1 or 3
        System.out.println( dice + " is 1 or 3" ); 
      } // else be quiet when 5
    } else { // even number 
      System.out.println( dice + " is one of 2, 4, 6 " ); 
    }
  }
}

How can we remove curly braces now? 

Sara says:

public class Thursday {
  public static void main(String[] args) {
    int dice = (int) (Math.random() * 6) + 1;
    // System.out.println( dice ); 
    if (dice % 2 == 1) { // odd number 
      if (dice <= 3) 
        System.out.println( dice + " is 1 or 3" ); 
    } else { // even number 
      System.out.println( dice + " is one of 2, 4, 6 " ); 
    }
  }
}

Jack says:

public class Thursday { 
  public static void main(String[] args) {
    int dice = (int) (Math.random() * 6) + 1;
    System.out.println( dice ); 
    if (dice % 2 == 1) { // odd number 
      if (dice <= 3) 
        System.out.println( dice + " is 1 or 3" ); 
    } else 
      System.out.println( dice + " is one of 2, 4, 6 " ); 
  }
}

Trevor says let's remove the pair of curly braces:

public class Thursday { 
  public static void main(String[] args) { 
    int dice = (int) (Math.random() * 6) + 1;
    System.out.println( dice ); 
    if (dice % 2 == 1) 
      if (dice <= 3) 
        System.out.println( dice + " is 1 or 3" ); 
      else 
        System.out.println( dice + " is one of 2, 4, 6 " ); 
  }
}

And as Ryan and Thomas explain this is not good. Program is now incorrect. 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> int i = 3;
> i
3
> i++ // value is 3 and then i becomes 4
3
> i
4
> i++ + 0 // value is 4 and i becomes 5
4
> i
5
> i++ + 1 // 6 and i is 6
6
> i
6
> i++ + i // 13 and i is 7 
13
> i
7
> i++ + i++ // 7 (and i becomes 8) + 8 (and i becomes 9) 
15
> i
9
> i++ + ++i // 9 (and i becomes 10) + 11 (and i stays 11)
20
> i
11