Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 61 of 151

How to render thin fonts more smoothly in CSS3 with HTML?

Samual Sam
Samual Sam
Updated on 13-Mar-2026 340 Views

Rendering thin fonts smoothly is crucial for creating visually appealing web interfaces. CSS3 provides several properties that help improve font rendering, especially for thin or light weight fonts that may appear jagged or pixelated on certain displays. Font Smoothing Properties To render thin fonts more smoothly, use the following combination of CSS properties − .smooth-font { text-rendering: optimizeLegibility !important; -webkit-font-smoothing: antialiased !important; -moz-osx-font-smoothing: grayscale !important; } For Google Chrome For specific optimization in WebKit-based browsers like Google Chrome, use − ...

Read More

C++ Program to Find GCD

Samual Sam
Samual Sam
Updated on 12-Mar-2026 15K+ Views

The Greatest Common Divisor (GCD) of two numbers is the largest number that divides both of them without leaving a remainder. For example, let's say we have two numbers 45 and 27 − 45 = 5 * 3 * 3 27 = 3 * 3 * 3 The common factors are 3 and 3, so the GCD of 45 and 27 is 9. Using Euclidean Algorithm (Modulo Method) The Euclidean algorithm finds the GCD by repeatedly replacing the larger number with the remainder of dividing the two numbers, until the remainder becomes 0. At that point, the other ...

Read More

How to write Java program to add two matrices

Samual Sam
Samual Sam
Updated on 11-Mar-2026 6K+ Views

To add two matrices −Create an empty matrixAt each position in the new matrix, assign the sum of the values in the same position from the given two matrices i.e. if A[i][j] and B[i][j] are the two given matrices then, the value of c[i][j] should be A[i][j] + B[i][j]Examplepublic class AddingTwoMatrices{    public static void main(String args[]){       int a[][]={{1,2,3},{4,5,6},{7,8,9}};       int b[][]={{1,1,1},{1,1,1},{1,1,1}};       int c[][]=new int[3][3];       for(int i = 0;i

Read More

How to open a plain text file in Java?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 433 Views

You can access a plain text using the File class.Exampleimport java.io.File; public class ReadFile {    public static void main(String[] args) {       File f = null;       String str = "data.txt";       try {          f = new File(str);          boolean bool = f.canExecute();          String a = f.getAbsolutePath();          System.out.print(a);          System.out.println(" is executable: "+ bool);       } catch (Exception e) {          e.printStackTrace();       }    } }Output C:\Users\data is executable: true

Read More

ByteBuffer asReadOnlyBuffer() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 585 Views

A read-only byte buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.ByteBuffer. The new buffer cannot have any modifications as it is a read-only buffer. However, the capacity, positions, limits etc. of the new buffer are the same as the previous buffer.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {     int n = 5;     try {       ByteBuffer buffer = ByteBuffer.allocate(5);     ...

Read More

Java Program to check if a Float is Infinite or Not a Number(NAN)

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

To check if a Float is isInfinite, use the isInfinite() method and to check for NAN, use the isNaN() method.Examplepublic class Demo {    public static void main(String[] args) {       float value1 = (float) 1 / 0;       boolean res1 = Float.isInfinite(value1);       System.out.println("Checking for isInfinite? = "+res1);       float value2 = (float) Math.sqrt(9);       boolean res2 = Float.isNaN(value2);       System.out.println("Checking for isNan? = "+res2);    } }OutputChecking for isInfinite? = true Checking for isNan? = false

Read More

File Path with double slash in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 1K+ Views

The double slash in the file path is required as to create the ’\’ character , another ‘\’ needs to be added to escape it. A program that demonstrates this is given as follows −Exampleimport java.io.File; public class Demo {    public static void main(String[] args) {       File file = new File("C:\jdk11.0.2\demo1.txt");       System.out.println(file);    } }The output of the above program is as follows −OutputC:\jdk11.0.2\demo1.txtNow let us understand the above program.The file path of the file is provided with double slash and then it is printed. A code snippet that demonstrates this is given ...

Read More

ByteBuffer allocateDirect() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 397 Views

A direct byte buffer can be allocated using the method allocateDirect() in the class java.nio.ByteBuffer. This method requires a single parameter i.e. the capacity in bytes and it returns the direct byte buffer. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ByteBuffer buffer = ByteBuffer.allocateDirect(n);          byte[] byteValues = { 7, 1, 6, 3, 8 ...

Read More

How to display random numbers less than 20 in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 367 Views

At first, create a Random class object −Random rand = new Random();Now, create a new array −int num; int arr[] = new int[10];Loop through and set the Random nextInt with 20 as parameter since you want random numbers less than 20 −for (int j = 0; j

Read More

How to display numbers in scientific notation in Java?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 6K+ Views

To display number in scientific notation, create NumberFormat object first −NumberFormat numFormat = newDecimalFormat();Now, let’s say you need to format the minimum value of Integer −int i = Integer.MIN_VALUE; System.out.println(i); numFormat = newDecimalFormat("0.######E0"); System.out.println(numFormat.format(i)); numFormat = newDecimalFormat("0.#####E0"); System.out.println(numFormat.format(i));Above, we have used format() method of the NumberFormat class.Exampleimport java.text.DecimalFormat; import java.text.NumberFormat; public class Demo {    public static void main(String args[]) {       NumberFormat numFormat = new DecimalFormat();       int i = Integer.MIN_VALUE;       System.out.println(i);       numFormat = new DecimalFormat("0.######E0");       System.out.println(numFormat.format(i));       numFormat = new DecimalFormat("0.#####E0");     ...

Read More
Showing 601–610 of 1,507 articles
« Prev 1 59 60 61 62 63 151 Next »
Advertisements