- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 267 Articles for Java8
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
480 Views
Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.ExampleFollowing is an example to find Fibonacci series of a given number using a recursive functionpublic class FibonacciSeriesUsingRecursion { public static long fibonacci(long number) { if ((number == 0) || (number == 1)) return number; else return fibonacci(number - 1) + fibonacci(number - 2); } public static void main(String[] args) { for (int counter = 0; counter
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
8K+ Views
Pascal's triangle is one of the classic example taught to engineering students. It has many interpretations. One of the famous one is its use with binomial equations.All values outside the triangle are considered zero (0). The first row is 0 1 0 whereas only 1 acquire a space in Pascal’s triangle, 0s are invisible. Second row is acquired by adding (0+1) and (1+0). The output is sandwiched between two zeroes. The process continues till the required level is achieved.AlgorithmTake a number of rows to be printed, n.Make outer iteration I for n times to print rows.Make inner iteration for J ... Read More
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
4K+ Views
Floyd's triangle, named after Robert Floyd, is a right-angled triangle, which is made using natural numbers. It starts at 1 and consecutively selects the next greater number in the sequence.AlgorithmTake a number of rows to be printed, n.Make outer iteration I for n times to print rowsMake inner iteration for J to IPrint KIncrement KPrint NEWLINE character after each inner iterationExampleimport java.util.Scanner; public class FloyidsTriangle { public static void main(String args[]){ int n, i, j, k = 1; System.out.println("Enter the number of lines you need in the FloyidsTriangle"); Scanner sc ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
The interface Set does not allow duplicate elements, therefore, create a set object and try to add each element to it using the add() method in case of repetition of elements this method returns false −If you try to add all the elements of the array to a Set, it accepts only unique elements so, to find duplicate characters in a given stringConvert it into a character array.Try to insert elements of the above-created array into a hash set using add method.If the addition is successful this method returns true.Since Set doesn't allow duplicate elements this method returns 0 when ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
511 Views
The java.util.Scanner class is a simple text scanner which can parse primitive types and strings using regular expressions.1. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.2. A scanning operation may block waiting for input.3. A Scanner is not safe for multi-threaded use without external synchronization.The nextInt() method of the Scanner class is used to read an integer value from the source.Exampleimport java.util.Scanner; public class ReadingNumbersFromUser { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter a number ::"); int num ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
8K+ Views
The * operator in Java is used to multiply two numbers. Read required numbers from the user using Scanner class and multiply these two integers using the * operator.Exampleimport java.util.Scanner; public class MultiplicationOfTwoNumbers { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter the value of the first number ::"); int a = sc.nextInt(); System.out.println("Enter the value of the first number ::"); int b = sc.nextInt(); int result = a*b; System.out.println("Product of the given two numbers ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
64K+ Views
Finding a year is a leap or not is a bit tricky. We generally assume that if a year number is evenly divisible by 4 is a leap year. But it is not the only case. A year is a leap year if −1. It is evenly divisible by 1002. If it is divisible by 100, then it should also be divisible by 4003. Except this, all other years evenly divisible by 4 are leap years.Algorithm1. Take integer variable year2. Assign a value to the variable3. Check if the year is divisible by 4 but not 100, DISPLAY "leap year"4. ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
841 Views
Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function. You can reverse a string using the recursive function as shown in the following program.ExampleLive Demopublic class StringReverse { public String reverseString(String str){ if(str.isEmpty()){ return str; } else { return reverseString(str.substring(1))+str.charAt(0); } } public static void main(String[] args) { StringReverse obj = new StringReverse(); String result = obj.reverseString("Tutorialspoint"); System.out.println(result); } }OutputtniopslairotuT
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
734 Views
Any whole number which is greater than 1 and has only two factors that is 1 and the number itself, is called a prime number. Other than these two number it has no positive divisor. For example −7 = 1 × 7Few prime numbers are − 1, 2, 3, 5, 7, 11 etc.Algorithm1. Take integer variable A2. Divide the variable A with (A-1 to 2)3. If A is not divisible by any value (A-1 to 2), except itself it is a prime number.4. Repeat this for all the numbers starting from 2 to the required limit.ExampleLive Demopublic class First100Primes { public static void main(String args[]){ for(int i = 2; i
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
3K+ Views
You can read data from the user using scanner class.Using the nextInt() method of this class get the number of elements from the user.Create an empty array.Store the elements entered by the user in the array created above.Finally, Add all the elements in the array and divide the sub by the number of elements.Exampleimport java.util.Scanner; public class AverageUsingArrays { public static void main(String args[]){ //Reading total no.of elements Scanner sc = new Scanner(System.in); System.out.println("Enter the number of elements/numbers"); int num = sc.nextInt(); ... Read More