Java program for Multiplication of Array elements

Venkata Sai
Updated on 18-Jun-2024 15:41:39

16K+ Views

To find the product of elements of an array.create an empty variable. (product)Initialize it with 1.In a loop traverse through each element (or get each element from user) multiply each element to product.Print the product.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class ProductOfArrayOfElements {    public static void main(String args[]){       System.out.println("Enter the required size of the array :: ");       Scanner s = new Scanner(System.in);       int size = s.nextInt();       int myArray[] = new int [size];       int product = 1;       System.out.println("Enter the elements of the ... Read More

Java program to print the Armstrong numbers between two numbers

Ankith Reddy
Updated on 18-Jun-2024 15:34:13

14K+ Views

An Armstrong number is a number which equals to the sum of the cubes of its individual digits. For example, 153 is an Armstrong number as −153 = (1)3 + (5)3 + (3)3 153 1 + 125 + 27 154 153Algorithm1. Take integer variable Arms. 2. Assign a value to the variable. 3. Split all digits of Arms. 4. Find cube-value of each digit. 5. Add all cube-values together. 6. Save the output to Sum variable. 7. If Sum equals to Arms print Armstrong Number. 8. If Sum does not equal to Arms print Not Armstrong Number.Example Below is an ... Read More

Java Program to convert from decimal to binary

Samual Sam
Updated on 18-Jun-2024 15:20:46

21K+ Views

To convert decimal to binary, Java has a method Integer.toBinaryString(). The method returns a string representation of the integer argument as an unsigned integer in base 2.Let us first declare and initialize an integer variable.int dec = 25;Convert it to binary.String bin = Integer.toBinaryString(dec);Now display the “bin” string, which consists of the Binary value. Here is the complete example.Example Live Demopublic class Demo {    public static void main( String args[] ) {       int dec = 25;       // converting to binary and representing it in a string       String bin = Integer.toBinaryString(dec);       System.out.println(bin);    } }Output11001

Java program to check occurrence of each character in String

Chandu yadav
Updated on 18-Jun-2024 15:18:37

18K+ Views

In order to find occurence of each character in a string we can use Map utility of Java. In Map a key could not be duplicate so make each character of string as key of Map and provide initial value corresponding to each key as 1 if this character does not inserted in map before. Now when a character repeats during insertion as key in Map increase its value by one. Continue this for each character untill all characters of string get inserted.Examplepublic class occurenceOfCharacter {    public static void main(String[] args) {       String str = "SSDRRRTTYYTYTR"; ... Read More

Java program to Count the number of digits in a given integer

George John
Updated on 18-Jun-2024 15:07:07

15K+ Views

Read a number from user. Create an integer (count) initialize it with 0. Divide the number with 10. till the number is 0 and for each turn increment the count.Exampleimport java.util.Scanner; public class CountingDigitsInInteger {    public static void main(String args[]){       Scanner sc = new Scanner(System.in);       int count = 0;       System.out.println("Enter a number ::");       int num = sc.nextInt();       while(num!=0){          num = num/10;          count++;       }       System.out.println("Number of digits in the entered integer are :: "+count);    } }OutputEnter a number :: 1254566 Number of digits in the entered integer are :: 7

Comparing Streams to Loops in Java

Rudradev Das
Updated on 18-Jun-2024 00:54:38

133 Views

Stream is a pipeline system, which is mainly used to aggregate some operations like (filter(), map(), forEach(), and collect()) in a Java environment. This function consists of a source which is followed by the value of zero and then terminate the operation. A function is an input output stream whis mainly depends on the input arguments. Every stream works when − It starts from a data source. Process the data elements through a pipeline. Terminates itself in a terminal operation. Example of Comparing Streams to Loops Here is an example − Benchmark Is Here Mode Cnt Score ... Read More

Comparing Two ArrayList In Java

Rudradev Das
Updated on 18-Jun-2024 00:08:35

462 Views

How to Compare Two ArrayList In Java? There are various methods available, to compare the two particular array lists by using a Java environment. It consists of the array lists, as they are same in the size and should contain with the same elements in that particular lists. Difference Methods to Compare Two ArrayList In Java Here are some process mentioned below − Java equals() method Java removeAll() method Java retainAll() method Java ArrayList.contains() method Java contentEquals() method java.util.ArrayList method For this process − This particular function has a single parameter value to be compared for the ... Read More

Compile Time Polymorphism in Java

Rudradev Das
Updated on 17-Jun-2024 23:56:42

174 Views

The polymorphism is a declaration of an object capacity present in a Java environment. It allows us to perform the same process in different manner. There are two types of polymorphism present in Java − Compile-time polymorphism method Run time polymorphism method Today, we are going to discuss about the compile time polymorphism by using the Method overloading and Operator overloading. Compile Time Polymorphism Example Here is an example − void ARBRDD() { ... } void ARBRDD(int num1 ) { ... } void ARBRDD(float num1) { ... } void ARBRDD(int num1 , float num2 ) { ... ... Read More

Compiler Class In Java

Rudradev Das
Updated on 17-Jun-2024 23:42:09

137 Views

What is Compiler Class In Java? A native code is a coding formation that can be run in a Java Virtual Machine. The compiler class, provides a support as well as give us a space to convert a Java code to a native code. This a public package which embedded in java.lang.Compiler.command() package in a Java environment. Example of a Compiler Class in Java Here is an example for a compiler class in Java − class of the NewClass$CompilerClass Name Value Is: null value Is the compilation successful here? : false value Is the compilation successful using str ... Read More

Compressing and Decompressing files in Java

Rudradev Das
Updated on 17-Jun-2024 23:27:13

259 Views

Reading data of a particular file and and compress some files into a zip, is a process of encapsulation in Java. There are two compressing and decompressing classes in a Java environment, which provides the data deflate compression format. They are − DeflaterOutputStream class − used to compress the files into a deflate format such as GZIPOutputStream. InflaterInputStream class − used to decompress the files in a deflate format such as GZIPInputStream. Example Here is an example of the process how we can compress a file into a Zip file in Java − try { File file ... Read More

Advertisements