-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh14_90_FunClass_PrintingInColours.java
More file actions
35 lines (29 loc) · 1.38 KB
/
Ch14_90_FunClass_PrintingInColours.java
File metadata and controls
35 lines (29 loc) · 1.38 KB
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
import java.util.Scanner;
public class Ch14_90_FunClass_PrintingInColours {
// Codes-
public static String RESET = "\u001B[0m";
public static String RED = "\u001B[31m";
public static String GREEN = "\u001B[32m";
public static String YELLOW = "\u001B[33m";
public static String BLUE = "\u001B[34m";
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
/* Printing in a specific colour Requires to Set ANSI codes:
Say , a variable RED ->
It includes Syntax
public static String RED = "ANSI code";
Here , public - access modifier
static - joins the code to class
String - denotes Variable type
RED - Variable Name (preffered color name)
ANSI codes are specific to the color. */
// Note : Whtie is called Reset as it again sets the colour to default.
System.out.print("Enter a Statement: "); String statement = input.nextLine();
System.out.println();
System.out.println("RED: " + RED + statement + RESET);
System.out.println("GREEN: " + GREEN + statement + RESET);
System.out.println("YELLOW: " + YELLOW + statement + RESET);
System.out.println("BLUE: " + BLUE + statement + RESET);
System.out.println("WHITE: " + RESET + statement);
}
}