Programming Articles - Page 2682 of 3366

Java Program to get timezone id strings

Samual Sam
Updated on 30-Jul-2019 22:30:25

229 Views

Let us get the timezone id strings for timezone America. For this, use the get.AvailableZoneIds() method −ZoneId.getAvailableZoneIds().stream().filter(s ->s.startsWith("America")) .forEach(System.out::println);With that, we have used the forEach to display all the timezones in America −America/Cuiaba America/Marigot America/El_Salvador America/Guatemala America/Belize America/Panama America/Managua America/Indiana/Petersburg America/Chicago America/Tegucigalpa America/Eirunepe America/Miquelon . . .Exampleimport java.time.ZoneId; public class Demo {    public static void main(String[] args) {       System.out.println("TimeZones in the US");       ZoneId.getAvailableZoneIds().stream().filter(s ->s.startsWith("America"))       .forEach(System.out::println);    } }OutputTimeZones in the US America/Cuiaba America/Marigot America/El_Salvador America/Guatemala America/Belize America/Panama America/Managua America/Indiana/Petersburg America/Chicago America/Tegucigalpa America/Eirunepe America/Miquelon America/Argentina/Catamarca America/Grand_Turk America/Argentina/Cordoba America/Araguaina America/Argentina/Salta America/Montevideo America/Manaus ... Read More

Java program to get milliseconds between dates

karthikeya Boyini
Updated on 05-Sep-2024 11:22:45

2K+ Views

In this article, we will learn to get milliseconds between dates in Java. We will be using the LocalDateTime class from java.time package and ChronoUnit.MILLIS of java.time.temporal package. ChronoUnit is an enum that is part of Java date and time API which represents a unit of time that is days, hours, minutes etc. Here, the MILLIS is a unit that represents the concept of a millisecond. Problem Statement Write a program in Jave to get milliseconds between dates. Below is the representation − Input Date One = 2024-09-04T05:40:19.817038951Date Two = 2019-04-10T11:20 Output Milliseconds between two dates = -170533219817 Steps to get milliseconds between dates ... Read More

Java Program to get the value stored in a byte as an unsigned integer

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

287 Views

Let us first create signed byte −byte signedVal = -100;Now convert a byte to an unsigned integer −int unsignedVal = Byte.toUnsignedInt(signedVal);Examplepublic class Demo {    public static void main(String[] args) {       byte signedVal = -100;       int unsignedVal = Byte.toUnsignedInt(signedVal);       System.out.println("Signed value (byte) = " + signedVal);       System.out.println("Unsigned value (byte) = " + unsignedVal);    } }OutputSigned value (byte) = -100 Unsigned value (byte) = 156

Java program to generate n distinct random numbers

Alshifa Hasnain
Updated on 22-Jan-2025 15:48:12

1K+ Views

In this article, we will learn to generate n distinct random numbers within a specified range, ensuring that no number is repeated in Java. Generating random numbers is a common problem in various applications such as simulations, games, and testing. Problem Statement In this problem, we are given a number n, and we need to generate n unique random numbers within a defined range, ensuring that no number is repeated. The range can be specified by the user, or it can be a default range based on the problem's requirements. Input int n = 10; Output [4, 6, 9, 1, ... Read More

How to get the IP Address of local computer using C/C++?

Akansha Kumari
Updated on 11-Jun-2025 18:01:43

9K+ Views

In this article, we will see how to get the Host name and IP address of the local system in an easier way using C and C++ program.  Getting IP Address of Local Computer For this, some standard networking functions are available in socket programming with header files like on Windows and , , on Linux. In this article we will mainly discuss three commonly used functions: Sr.No ... Read More

C/C++ Struct vs Class

Smita Kapse
Updated on 30-Jul-2019 22:30:25

430 Views

In C++ the structure and class are basically same. But there are some minor differences. These differences are like below.The class members are private by default, but members of structures are public. Let us see these two codes to see the differences.Example#include using namespace std; class my_class {    int x = 10; }; int main() {    my_class my_ob;    cout

Difference between void main and int main in C/C++

Akansha Kumari
Updated on 09-Jun-2025 15:28:49

38K+ Views

The main() function in C and C++ is anentry point of a program from where the execution begins. And there are two common ways available to define the main function; int main() and void main(). In this following article we will learn the differences between these two in detail. The main() function is the same like other functions, which takes arguments and returns some value. A point to keep in mind is that the execution of a program always begins from the main() function. When a program runs, the operating system calls the main() and the value returned from it ... Read More

How to generate different random numbers in a loop in C++?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

4K+ Views

Let us see how to generate different random numbers using C++. Here we are generating random numbers in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C++ library. The function void srand(unsigned int seed) seeds the random number generator used by the function rand.The declaration of srand() is like below −void srand(unsigned int seed)It takes a parameter called seed. This is an integer value to be used as seed by the pseudo-random number generator algorithm. This function returns nothing.To get the number ... Read More

Returning multiple values from a C++ function

Aman Kumar
Updated on 12-Jun-2025 17:51:03

10K+ Views

In C++, we cannot return multiple values from a function directly. But, by using some methods (i.e., techniques), we can return multiple values from a function. How to Return Multiple Values from a Function? A function can return only one value using the return statement. We can return multiple values (more than one value) from a function by using the "call by address" and "call by reference" approach in the invoker function. Return Multiple Values from a Function Using Call by Address In C++, the call is an address, also known as a call by pointer. It passes ... Read More

Checking if a double (or float) is NaN in C++

Aman Kumar
Updated on 18-Jun-2025 18:47:53

14K+ Views

In this article we will check whether a double or floating point number is NaN (Not a Number) in C++. Checking if a Double or Floating Point Number is NaN To check, we can utilise the isnan() method. The isnan() function is available in the cmath library. This function was introduced in C++ version 11. So From C++11 next, we can use this function. The isnan() function is used to determine whether a double or floating point number is not-a-number (NaN) value. Return true if num is NaN, false otherwise. C++ Program to Check Double or Float Number is NaN ... Read More

Advertisements