Java console and terminal color

Java Console color //Java console color constants public static final String TEXT_RED = "\u001B[31m"; public static final String TEXT_BLACK = "\u001B[30m"; public static final String TEXT_GREEN = "\u001B[32m"; public static final String TEXT_BLUE = "\u001B[34m"; public static final String TEXT_RESET = "\u001B[0m"; public static final String TEXT_PURPLE = "\u001B[35m"; public static final String TEXT_CYAN = … Read more

Console log java

try(Scanner scan=new Scanner(System.in)){ // In java, read from console String inputString=scan.nextLine(); //In Java, write to console System.out.println(inputString); }

ANSI Colors Java

public class ConsoleColors { // Reset public static final String RESET = “\033[0m”; // Text Reset // Regular Colors public static final String BLACK = “\033[0;30m”; // BLACK public static final String RED = “\033[0;31m”; // RED public static final String GREEN = “\033[0;32m”; // GREEN public static final String YELLOW = “\033[0;33m”; // YELLOW … Read more

RGB to HEX java

class RGBToHex { public static void main(String[] args) { int r = 25; int g = 92; int b = 155; String hex = String.format(” System.out.println(hex); } } Output: #195C9B

Java full screen jFrame

frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setUndecorated(true); frame.setVisible(true);

import math java

import java.lang.Math.*; Example class MathJava { public static void main(String[] args) { // Declaring the variables int num1 = -2; float num2 = .8f; // Printing the values System.out.println(“Initial value of int : “+num1); System.out.println(“Initial value of int : “+num2); // Use of .abs() method to get the absoluteValue int Absi = Math.abs(num1); float Absf … Read more

Java int to roman

import java.util.TreeMap; class IntToRoman { public final static String toRoman(int number, TreeMap romanIdentifiers) { int l = romanIdentifiers.floorKey(number); if (number == l) { return romanIdentifiers.get(number); } return romanIdentifiers.get(l) + toRoman(number – l, romanIdentifiers); } public static void main(String[] args) { final TreeMap romanIdentifiers = new TreeMap(); romanIdentifiers.put(1000, “M”); romanIdentifiers.put(900, “CM”); romanIdentifiers.put(500, “D”); romanIdentifiers.put(400, “CD”); romanIdentifiers.put(100, … Read more

jLabel text center

JLabel label = new JLabel(“Label Text Here”, SwingConstants.CENTER);