-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBellSound.java
executable file
·57 lines (50 loc) · 2.03 KB
/
BellSound.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Make a bell sound in the terminal!
*/
public class BellSound {
public static void main(String[] args) throws InterruptedException {
System.out.println("Make a bell sound (🔔 turn your volume up!) by sending the ASCII code identified by the number 7 to the terminal");
{
System.out.println("Once!");
System.out.write(7);
System.out.flush();
Thread.sleep(800);
}
{
// This is the same thing. Binary is rarely used in Java source code, but if you are doing something low-level like
// toying with ASCII and using a visual aid like this ASCII table (https://en.wikipedia.org/wiki/ASCII#/media/File:USASCII_code_chart.png)
// which has binary values on the X and Y axes, then it can be educational to use binary.
System.out.println("Twice!");
System.out.write(0b00000111);
System.out.flush();
Thread.sleep(800);
}
{
// This is the same thing. Hexadecimal values are often used in source code to express terminal control
// characters.
System.out.println("Thrice!");
System.out.write(0x7);
System.out.flush();
Thread.sleep(800);
}
{
// This is the same thing. Unicode values are often used in source code to express terminal control
// characters.
System.out.println("A fourth time!");
System.out.write('\u0007');
System.out.flush();
Thread.sleep(800);
}
{
// This is the same thing. Unicode characters can be conveniently expressed in string constants in Java code.
System.out.println("\u0007A fifth time!");
System.out.flush();
Thread.sleep(800);
}
{
// This is the same thing. Octal numbers can be conveniently expressed in string constants in Java code.
System.out.println("\007A sixth and final bell!");
}
System.out.println("This code is known as a 'control character', as are all codes in the decimal range 0-31. Read more about control characters on Wikipedia: https://en.wikipedia.org/wiki/ASCII#Control_characters");
}
}