(Java programming Example for Beginners) Java FileInputStream Class In this tutorial, we will learn about Java FileInputStream and its methods with the help of examples. The FileInputStream class of the java.io package can be used to read data (in bytes) from files. It extends the InputStream abstract class. Before we learn about FileInputStream, make sure to know about Java Files. Create a FileInputStream …
Month: March 2021
(Python Example for Beginners) Write a Python program to create a Pythagorean theorem calculator. Note : In mathematics, the Pythagorean theorem, also known as Pythagoras’ theorem, is a fundamental relation in Euclidean geometry among the three sides of a right triangle. It states that the square of the hypotenuse (the side opposite the right …
(Python Example for Beginners) Write a Python program to create a simple math quiz. Sample Solution: Python Code: import random def display_intro(): title = “** A Simple Math Quiz **” print(“*” * len(title)) print(title) print(“*” * len(title)) def display_menu(): menu_list = [“1. Addition”, “2. Subtraction”, “3. Multiplication”, “4. Integer Division”, “5. Exit”] print(menu_list[0]) …
(Java programming Example for Beginners) Java I/O Streams In this tutorial, we will learn about Java input/output streams and their types. In Java, streams are the sequence of data that are read from the source and written to the destination. An input stream is used to read data from the source. And, an output stream is used to write …
(Python Example for Beginners) Write a Python program to parse math formulas and put parentheses around multiplication and division. Sample Solution: Python Code: import ast def recurse(node): if isinstance(node, ast.BinOp): if isinstance(node.op, ast.Mult) or isinstance(node.op, ast.Div): print(‘(‘, end=”) recurse(node.left) recurse(node.op) recurse(node.right) if isinstance(node.op, ast.Mult) or isinstance(node.op, ast.Div): print(‘)’, end=”) elif isinstance(node, ast.Add): print(‘+’, …
(Java programming Example for Beginners) Java ListIterator Interface In this tutorial, we will learn about the Java ListIterator interface with the help of an example. The ListIterator interface of the Java collections framework provides the functionality to access elements of a list. It is bidirectional. This means it allows us to iterate elements of a list in …
(Java programming Example for Beginners) Java Iterator Interface In this tutorial, we will learn about the Java Iterator interface with the help of an example. The Iterator interface of the Java collections framework allows us to access elements of a collection. It has a subinterface ListIterator. All the Java collections include an iterator() method. This method returns an instance of …
(Python Example for Beginners) Write a Python program to calculate the standard deviation of the following data. Sample Solution: Python Code: import math import sys def sd_calc(data): n = len(data) if n <= 1: return 0.0 mean, sd = avg_calc(data), 0.0 # calculate stan. dev. for el in data: sd += (float(el) – …
(Python Example for Beginners) Write a Python program to randomly select an item from a list. Sample Solution: Python Code: import random color = [‘Red’, ‘Green’, ‘Black’, ‘Orange’, ‘Black’] print(random.choice(color)) Sample Output: Black Python Example – Write a Python program to randomly select an item from a list Free Machine Learning & …
(Java programming Example for Beginners) Java Algorithms In this tutorial, we will learn about different algorithms provided by the Java collections framework with the help of examples. The Java collections framework provides various algorithms that can be used to manipulate elements stored in data structures. Algorithms in Java are static methods that can be used …