Count D-Digit Positive Integers with 0 as a Digit in C++

Ayush Gupta
Updated on 05-Feb-2020 07:29:56

159 Views

In this tutorial, we will be discussing a program to find the numbers having ‘d’ digits with 0 as a digit.For this we will be provided with a number ‘d’. Our task is to count and print the number of positive integers having ‘d’ digits and 0 as one of their digit.Example Live Demo#include using namespace std; //counting the number of 'd' digit numbers int count_num(int d) {    return 9*(pow(10,d-1) - pow(9,d-1)); } int main(){    int d = 1;    cout

Cost to Make a String Panagram in C++

Ayush Gupta
Updated on 05-Feb-2020 07:27:08

169 Views

In this tutorial, we will be discussing a program to find the cost of making a string panagram.For this we will be provided with an array of integers. Our task is to convert the given string into a panagram and calculate the cost of doing that with the help of the array provided with the costs of adding characters.Example Live Demo#include using namespace std; //calculating the total cost of //making panagram int calc_cost(int arr[], string str) {    int cost = 0;    bool occurred[26] = { false };    for (int i = 0; i < str.size(); i++)   ... Read More

Cost to Balance the Parentheses in C++

Ayush Gupta
Updated on 05-Feb-2020 07:23:37

135 Views

In this tutorial, we will be discussing a program to find the cost to balance the parentheses.For this we will be provided with a sequence of brackets. Our task is to balance those parentheses in the equation by shifting their position by one and print -1 if balancing them isn’t possible.Example Live Demo#include using namespace std; int costToBalance(string s) {    if (s.length() == 0)       cout

Cost of Painting N x M Grid in C++

Ayush Gupta
Updated on 05-Feb-2020 07:17:06

194 Views

In this tutorial, we will be discussing a program to find the cost of painting n*m grid.For this we will be provided with two integers n and m. Our task is to calculate the minimum cost of painting a n*m grid is the cost of painting a cell is equal to the number of painted cells adjacent to it.Example Live Demo#include using namespace std; //calculating the minimum cost int calc_cost(int n, int m){    int cost = (n - 1) * m + (m - 1) * n;    return cost; } int main(){    int n = 4, m = 5;    cout

Correct the Random Pointer in Doubly Linked List in C++

Ayush Gupta
Updated on 05-Feb-2020 07:14:03

183 Views

In this tutorial, we will be discussing a program to correct the random pointer in a doubly linked list.For this we will be provided with a doubly linked list with one node having a random pointer. Our task is to rectify the element to whom the pointer should be pointing i.e the element next to it.Example Live Demo#include using namespace std; //node structure for doubly linked list struct node {    int data;    node* next;    node* prev; }; //new node creation node* newNode(int data){    node* temp = new node;    temp->data = data;    temp->next = temp->prev ... Read More

Access Java Package from Another Package

Smita Kapse
Updated on 04-Feb-2020 11:26:52

6K+ Views

You can understand it using an example where a Boss class is defined in payroll package.package payroll; public class Boss {    public void payEmployee(Employee e) {       e.mailCheck();    } }if the Employee class is not in the payroll package? The Boss class must then use one of the following techniques for referring to a class in a different package.The fully qualified name of the class can be used. For example −payroll.EmployeeThe package can be imported using the import keyword and the wild card (*). For example −import payroll.*;The class itself can be imported using the import ... Read More

Use Classes in Other Package in Java

Ramu Prasad
Updated on 04-Feb-2020 11:21:21

923 Views

You can understand it using an example where a Boss class is defined in payroll package.package payroll; public class Boss {    public void payEmployee(Employee e) {       e.mailCheck();    } }if the Employee class is not in the payroll package? The Boss class must then use one of the following techniques for referring to a class in a different package.The fully qualified name of the class can be used. For example −payroll.EmployeeThe package can be imported using the import keyword and the wildcard (*). For example −import payroll.*;The class itself can be imported using the import keyword. ... Read More

Use Sub-package in Java

Sravani S
Updated on 04-Feb-2020 11:12:22

1K+ Views

Subpackages are similar to sub-directories. Consider an example. The company had a com.apple.computers package that contained a Dell.java source file, it would be contained in a series of subdirectories like this −....\com\apple\computers\Dell.javaAt the time of compilation, the compiler creates a different output file for each class, interface, and enumeration defined in it. The base name of the output file is the name of the type, and its extension is .class.For example −// File Name:Dell.java package com.apple.computers; public class Dell { } class Ups { }Now, compile this file as follows using -d option −$javac -d.Dell.javaThe files will be compiled as ... Read More

Load Classes at Runtime from a Folder or Java Package

Abhinaya
Updated on 04-Feb-2020 11:06:03

912 Views

Using CLASSPATH, you can load any classes at runtime.Like the .java source files, the compiled .class files should be in a series of directories that reflect the package name. However, the path to the .class files does not have to be the same as the path to the .java source files. You can arrange your source and class directories separately, as −\sources\com\apple\computers\Dell.java \classes\com\apple\computers\Dell.classBy doing this, it is possible to give access to the classes directory to other programmers without revealing your sources. You also need to manage source and class files in this manner so that the compiler and the ... Read More

Java Constructor Return a Value - What You Need to Know

Priya Pallavi
Updated on 04-Feb-2020 10:54:52

989 Views

No. Java constructor cannot return a value. If required, just create a method which calls the required constructor and returns the required value. See the example below.public class Tester {    public Tester(){}    public static Tester getInstance(){       Tester tester = new Tester();        return tester;    } }

Advertisements