Found 267 Articles for Java8

Java Program to Convert Character to String

Samual Sam
Updated on 13-Mar-2020 11:23:34

520 Views

The toString() method of the Character class converts the character to string. You can use this method to convert the given character to String.Exampleimport java.util.Scanner; public class CharToString {    public static void main(String args[]){       System.out.println("Enter a character ::");       Scanner sc = new Scanner(System.in);       char ch = sc.next().charAt(0);       String str = Character.toString(ch);       System.out.println(str);    } }OutputEnter a character :: h h

Java program to calculate the percentage

Lakshmi Srinivas
Updated on 14-Jun-2024 13:37:08

28K+ Views

Percent means percent (hundreds), i.e., a ratio of the parts out of 100. The symbol of a percent is %. We generally count the percentage of marks obtained, return on investment etc. The percentage can go beyond 100% also.For Example, assuming that we have total and a part. So we say what part is what percent of total and should be calculated as −percentage = ( part / total ) × 100AlgorithmBelow is the algorithm to calculate percentage in Java:1. Collect values for part and total 2. Apply formula { percentage = ( part / total ) × 100 } ... Read More

Java program to calculate mean of given numbers

Ankith Reddy
Updated on 19-Jun-2020 14:54:39

5K+ Views

Mean is an average value of given set of numbers. It is calculated similarly to that of the average value. Adding all given number together and then dividing them by the total number of values produces mean.For Example Mean of 3, 5, 2, 7, 3 is (3 + 5 + 2 + 7 + 3) / 5 = 4AlgorithmTake an integer set A of n values.Add all values of A together.Divide result of Step 2 by n.The result is mean of A's values.Programpublic class CaculatingMean {    public static void main(String args[]){       float mean;       int ... Read More

Java program to calculate the average of numbers in Java

karthikeya Boyini
Updated on 13-Mar-2020 11:17:58

11K+ Views

An average of a set of numbers is their sum divided by their quantity. It can be defined as −average = sum of all values / number of valuesHere we shall learn how to programmatically calculate average.Algorithm1. Collect integer values in an array A of size N. 2. Add all values of A. 3. Divide the output of Step 2 with N. 4. Display the output of Step 3 as average.ExampleLive Demopublic class AverageOfNNumbers {    public static void main(String args[]){       int i,total;       int a[] = {0,6,9,2,7};       int n = 5;       total = 0;       for(i=0; i

Java program to find the cube root of a given number

George John
Updated on 19-Jun-2020 14:51:46

1K+ Views

Following is an example to find the cube root of a given number.Programimport java.util.Scanner; public class FindingCubeRoot {    public static void main(String args[]){       double i, precision = 0.000001;       System.out.println("Enter a number ::");       Scanner sc = new Scanner(System.in);       int num = sc.nextInt();       for(i = 1; (i*i*i)

Java program to find a cube of a given number

Samual Sam
Updated on 18-Jun-2024 15:48:41

13K+ Views

Cube of a value is simply three times multiplication of the value with self.For example, cube of 2 is (2*2*2) = 8.AlgorithmSteps to find a cube of a given number in Java programming:Take integer variable A.Multiply A three times.Display result as Cube.Exampleimport java.util.Scanner; public class FindingCube {    public static void main(String args[]){       int n = 5;       System.out.println("Enter a number ::");       Scanner sc = new Scanner(System.in);       int num = sc.nextInt();       System.out.println("Cube of the given number is "+(num*num*num));    } }OutputEnter a number :: 5 Cube of the given number is 125

Java program to calculate mode in Java

Chandu yadav
Updated on 13-Mar-2020 10:54:18

12K+ Views

In statistics math, a mode is a value that occurs the highest numbers of time. For Example, assume a set of values 3, 5, 2, 7, 3. The mode of this value set is 3 as it appears more than any other number.Algorithm1.Take an integer set A of n values. 2.Count the occurrence of each integer value in A. 3.Display the value with the highest occurrence.ExampleLive Demopublic class Mode {    static int mode(int a[], int n) {       int maxValue = 0, maxCount = 0, i, j;       for (i = 0; i < ... Read More

Java program to find the permutation when the values n and r are given

Lakshmi Srinivas
Updated on 13-Mar-2020 10:52:12

219 Views

Permutation refers a number of ways in which set members can be arranged or ordered in some fashion. The formula of permutation of arranging k elements out of n elements is −nPk = n! / (n - k)!Algorithm1. Define values for n and r. 2. Calculate factorial of n and (n-r). 3. Divide factorial(n) by factorial(n-r). 4. Display result as a permutation.Exampleimport java.util.Scanner; public class Permutation {    static int factorial(int n) {       int f;       for(f = 1; n > 1; n--){          f *= n;       ... Read More

Java program to find the square root of a given number

Arjun Thakur
Updated on 13-Mar-2020 10:49:49

1K+ Views

The process of finding the square root of a number can be divided into two steps. One step is to find integer part and the second one is for fraction part.AlgorithmDefine value n to find the square root of.Define variable i and set it to 1. (For integer part)Define variable p and set it to 0.00001. (For fraction part)While i*i is less than n, increment i.Step 4 should produce the integer part so far.While i*i is less than n, add p to i.Now i have the square root value of n.ExampleLive Demopublic class SquareRoot {    public static void main(String ... Read More

Java program to find the Frequency of a character in a given String

karthikeya Boyini
Updated on 24-Jun-2024 15:42:49

5K+ Views

To find the Frequency of a character in a given String Read a string from the user. Read the character. Create an integer variable initialize it with 0. Compare each character in the given string with the entered character increment the above created integer variable each time a match occurs.Exampleimport java.util.Scanner; public class FrequencyOfACharacter {    public static void main(String args[]){       System.out.println("Enter a string value ::");       Scanner sc = new Scanner(System.in);       String str = sc.nextLine();       System.out.println("Enter a particular character ::");       char character = sc.nextLine().charAt(0);       int count = 0;       for (int i=0; i

Advertisements