Generate Array of First N Prime Numbers in JavaScript

Shriansh Kumar
Updated on 30-Sep-2024 16:01:16

2K+ Views

We are required to write a JavaScript function that takes in a number n and returns an array that contains first n prime numbers. We know that prime numbers are those numbers that are only divisible by 1 and themselves like 2, 3, 19, 37, 73 etc. Let's understand the problem with an example − Input: n = 6; Output: prime_numbers = [ 2, 3, 5, 7, 11, 13 ] Using Iteration We will first write a function that checks whether a given number is prime or not and then run a loop till the given number n ... Read More

Get CPU Serial Number for Windows Machine in Java

Shriansh Kumar
Updated on 30-Sep-2024 15:58:31

1K+ Views

The serial number of a CPU is a unique identifier which is given to a particular CPU by the manufacturer to each of them. Its main purpose is to track and identify the hardware for warranty claim. In this article, we are going to write a java program to get CPU serial number for windows machine. Central Processing Unit, in short CPU, is the brain of the computer. Using WMIC Command In this approach, we will use wmic command in java code. The wmic is a command line tool for working with Windows management. It stands for Windows Management Instrumentation ... Read More

Display Names of Weekdays in Calendar Year Using Java

Shriansh Kumar
Updated on 30-Sep-2024 15:56:38

796 Views

There are 5 weekdays in a week, which are Monday, Tuesday, Wednesday, Thursday and Friday. The two remaining days i.e. Saturday and Sunday make up the weekend. In this article, we will learn how to write a Java program to display name of the weekdays in a calendar year. Using the DateFormatSymbols Class The Java standard library's java.text package contains the DateFormatSymbols class which provides methods for retrieving and setting the following date and time symbols − Month and day names and abbreviations Day of the week names and abbreviations Era names AM/PM strings Time Zone Names and ... Read More

Display Current Time in Another Time Zone Using Java

Shriansh Kumar
Updated on 30-Sep-2024 15:54:09

2K+ Views

A time zone is a region of the globe that observes a uniform standard time for legal, commercial, and social purposes. Suppose you have an application that is running in India as well as Japan. Here, you can't use the same time zone for both regions. Therefore, it is necessary to display time in different time zones. Java provides various built-in classes like TimeZone and ZoneId and methods like getTimeZone() that can help in displaying the current time in another time zone. However, before using them, you must import them into your Java program. Using getTimeZone() and setTimeZone() Methods ... Read More

Print Summation of Numbers in Java

Shriansh Kumar
Updated on 30-Sep-2024 15:46:44

894 Views

Suppose you are given a set of numbers, your task is to write a Java program to print their summation. To find summation, you need to add all the given numbers with the help of addition operator. In Java, a set of numbers can be represented by an array. Let's understand the problem with an example − Example Scenario: Input: number_set = 34, 11, 78, 40, 66, 48; Output: summation = 277 Sum of all the numbers is 277 as 34 + 11 + 78 + 40 + 66 + 48 = 277. Using Iteration The most ... Read More

Shimmer Effect Using CSS

Shubham Vora
Updated on 30-Sep-2024 15:20:34

9K+ Views

To create shimmer effect using CSS, we will be using CSS animations and linear-gradient properties. Shimmer effect is an animation effect used in many webpages while loading the web page. In this article we are having a layout of a box having two other child boxes, our task is to create a shimmer effect using CSS. Steps to Create Shimmer Effect We will be following below mentioned steps to create shimmer effect using CSS. We are having two boxes wrapped inside a div container. The container class sets the dimension of ... Read More

Telematics: Definition, Tools, Applications, and Examples

Shirjeel Yunus
Updated on 30-Sep-2024 11:55:43

766 Views

What is Telematics? Telematics is a combination of two technologies which include telecommunications and informatics. Telecommunications includes phone lines and cables while computer systems are included in informatics. The telematics technology is used in commercial fleet vehicles. The data is transmitted during the vehicle movement with the help of wireless telematics devices and black box technologies. The data that is transmitted include − Usage of the vehicle Maintenance Servicing Fleet management can also be performed with the help of telematics. The technology can be used to get the knowledge of vehicles in the entire fleet related to their ... Read More

Render HTML String Preserving Spaces and Line Breaks

Tanya Sehgal
Updated on 30-Sep-2024 09:54:39

374 Views

Sometimes while writing the content of an HTML file, there might be the need to preserve blank spaces and line breaks. You might have noticed when you try to write something in the paragraph tag or the tag that has a lot of white spaces or a line break, it is not visible when the HTML page is rendered in the web browser. This article will show how to preserve those spaces while rendering the HTML page. Render an HTML String Preserving Spaces and Line Breaks Using HTML pre Tag ... Read More

Java Regex to Exclude a Specific String Constant

Arnab Chakraborty
Updated on 29-Sep-2024 02:51:09

2K+ Views

In this program, we will use a regular expression to check if a given string does not contain the substring "kk" using Java. The regular expression ^((?!kk).)*$ is designed to match strings that do not include the "kk" pattern anywhere in the string. The program will evaluate a sample string and print whether or not it contains "kk". Problem Statement Write a program in Java for checking whether a given string contains the substring "kk." If the string does not contain "kk" the program will return true otherwise it will return false. Input String s = "tutorials" Output true ... Read More

Find Longest Common Prefix Using Word by Word Matching in Java

Prabhdeep Singh
Updated on 29-Sep-2024 02:50:52

1K+ Views

In this article, we will explore how to find the longest common prefix among a given set of strings using two different approaches in Java. We will first discuss an approach that compares all strings directly to find the longest prefix and then move to a word-by-word matching approach.  Problem Statement We are given a set of strings and we have to find the common prefix among all of them. A prefix is a substring for a string that contains the zero index and could be of any length from 1 to a complete string. Input 1 string arr[] = ... Read More

Advertisements