Program DescriptionFloyd's triangle is a right-angled triangular array of natural numbers, used in computer science education. It is named after Robert Floyd. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner1 15 14 13 12 11 2 3 10 9 8 7 4 5 6 6 ... Read More
To input multiple values from user in one line, the code is as follows −Example Live Demoimport java.util.Scanner; public class Demo { public static void main(String[] args) { System.out.print("Enter two floating point values : "); Scanner my_scan = new Scanner(System.in); double double_val = my_scan.nextFloat(); int int_val = my_scan.nextInt(); System.out.println("The floating point value is : " + double_val + " and the integer value is : " + int_val); } }Input56.789 99OutputEnter two floating point values : The floating point value is ... Read More
Program DescriptionPrint the Solid and Hollow Rhombus Patterns as show belowAlgorithmFor Hollow Rhombus −Accept the Number of Rows for Hollow Rhombus from the User Create a Hollow Rhombus containing the same number of Rows specified by the User. Print the first row containing the number of stars same as the number of rows. Print the second row containing the first and last star as show in the output and leave the spaces between first and the last star. Do the same till you reach the last Row. Print the last row containing the number of stars same as the number ... Read More
The ‘interrupt’ function can be used in Java to interrupt the execution of a thread with the help of the exception InterruptedException.The below example shows how the currently executing thread stops execution (because of a new exception raised in the catch block) once it is interrupted −Example Live Demopublic class Demo extends Thread { public void run() { try { Thread.sleep(150); System.out.println("In the 'run' function inside try block"); } catch (InterruptedException e) { ... Read More
While working with Kotlin, Java libraries and frameworks can be used. This can be done with the help of advanced frameworks, without having to change the whole project. Java and Kotlin co-exist and can be present in the same project.Kotlin code can be placed inside Android Studio, without making the whole project in Kotlin.It is an open source platform that also helps in quick development of projects. It is easy, and readable, and considerably requires lesser coding in comparison to Java.Kotlin was developed by JetBrains, and IntelliJ is the IDE which Android Studio also uses.Kotlin plugin can be installed and ... Read More
JavaFX Button class provides the setOnAction() method that can be used to set an action for the button click event. An EventHandler is a functional interface and holds only one method is the handle() method.Syntax@FunctionalInterface public interface EventHandler extends EventListenerIn the below example, we can able to implement event handling of JavaFX by using a lambda expression.Exampleimport javafx.application.*; import javafx.beans.property.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class LambdaWithJavaFxTest extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) throws Exception { ... Read More
Program DescriptionWrite a program to print lower triangular matrix and upper triangular matrix of an Array.Triangular MatrixA Triangular matrix is one that is either lower triangular or upper triangular.Lower Triangular MatrixA square matrix is called lower triangular if all the entries above the main diagonal are zero.Upper Triangular MatrixA square matrix is called upper triangular if all the entries below the main diagonal are zero.A matrix of the form$${\displaystyle L={\begin{bmatrix}\ell _{1, 1}&&&&0\\ell _{2, 1}&\ell _{2, 2}&&&\\ell _{3, 1}&\ell _{3, 2}&\ddots &&\\vdots &\vdots &\ddots &\ddots &\\ell _{n, 1}&\ell _{n, 2}&\ldots &\ell _{n, n-1}&\ell _{n, n}\end{bmatrix}}}$$is called a lower triangular matrix or left triangular matrix, and analogously a matrix of the form$${\displaystyle U={\begin{bmatrix}u_{1, 1}&u_{1, 2}&u_{1, ... Read More
To get sum of list with stream filter in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { List my_list = new ArrayList(); my_list.add(11); my_list.add(35); my_list.add(56); my_list.add(78); my_list.add(91); System.out.println(sum(my_list)); } public static int sum(List my_list) { System.out.println("In the main function, the sum of list with filter is "); return my_list.stream().filter(i -> i > 5).mapToInt(i -> i).sum(); } ... Read More
While writing any piece of code in Java, there is a certain set of rules and regulations that need to be followed, that is considered as a standard. For example − A class contains variables, and functions. The functions can be used to work with the variables. Classes can be extended, and improvised too.Basic structureList of packages that are imported; public class { Constructor (can be user defined or implicitly created) { Operations that the constructor should perform; } Data elements/class data members; User-defined functions/methods; public static void main (String ... Read More
The DoubleFunction is a built-in functional interface defined in java.util.function package. This interface accepts one double-valued parameter as input and returns a value of type R. As this is a functional interface, it can be used as an assignment target for a lambda expression or method reference. DoubleFunction interface having only one abstract method, apply().Syntax@FunctionalInterface public interface DoubleFunction { R apply(double value); }Exampleimport java.util.function.DoubleFunction; public class DoubleFunctionTest { public static void main(String[] args) { DoubleFunction getGrade = marks -> { // lambda expression if(marks > 90 && marks 70 && marks 50 && marks
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP