Single Dimensional Array in Java

V Jyothi
Updated on 17-Jun-2020 08:12:12

982 Views

Following is a simple example of a single dimensional array.Example Live Demopublic class Tester {    public static void main(String[] args) {       double[] myList = {1.9, 2.9, 3.4, 3.5};       // Print all the array elements       for (double element: myList) {          System.out.print(element + " ");       }    } }Output1.9 2.9 3.4 3.5

Rod Cutting

Samual Sam
Updated on 17-Jun-2020 08:11:06

7K+ Views

A rod is given of length n. Another table is also provided, which contains different size and price for each size. Determine the maximum price by cutting the rod and selling them in the market.To get the best price by making a cut at different positions and comparing the prices after cutting the rod.Let the f(n) will return the max possible price after cutting a row with length n. We can simply write the function f(n) like this.f(n) := maximum value from price[i]+f(n – i – 1), where i is in range 0 to (n – 1).Input and OutputInput:The price ... Read More

Shortest Common Super Sequence

Chandu yadav
Updated on 17-Jun-2020 08:09:32

280 Views

Shortest common super-sequence is a sequence where each element of both of the given sequences is present. In other words, we can say that the given two strings, both are sub-sequence of Shortest Common Super-Sequence.When there are no common characters in two strings, then we can simply concatenate them to get Super-sequence. But when they have some common characters, then firstly we have to find the longest string, then add extra characters of the other string.Input and OutputInput: Two strings. “ABCDEF” and “XYDEF” Output: The length of the shortest common super-sequence. Here the super-sequence is “ABCDEFXY”. So the length is ... Read More

Ugly Numbers

George John
Updated on 17-Jun-2020 08:04:29

4K+ Views

Ugly numbers are those number whose prime factors are 2, 3 or 5. From 1 to 15, there are 11 ugly numbers 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15. The numbers 7, 11, 13 are not ugly because they are prime. The number 14 is not ugly because in its prime factor the 7 will come.In this program, we will try to find the nth ugly number.Input and OutputInput: Take the term number. Say it is 10 Output: The 10th ugly number is 12AlgorithmgetUglyNumbers(n)Input: The number of terms.Output: Find nth Ugly numbers.Begin    define array named ... Read More

Method of Object Class in Java

vanithasree
Updated on 17-Jun-2020 08:02:02

2K+ Views

Following are various methods of Object class −protected Object clone() - Used to create and return a copy of this object. boolean equals(Object obj) - Used to indicate whether some other object is "equal to" this one.protected void finalize() - garbage collector calls this method on an object when it determines that there are no more references to the object.Class getClass() - Used to get the runtime class of this Object.int hashCode() - Used to get a hash code value for the object.void notify() - Used to wake up a single thread that is waiting on this object's monitor.void notifyAll() - ... Read More

Word Wrap Problem

karthikeya Boyini
Updated on 17-Jun-2020 07:54:57

2K+ Views

A sequence of words is given, there is a limit on the number of characters for each line. By putting line breaks, in such a way that lines are printed clearly.The lines must be balanced, when some lines have lots of extra spaces and some lines are containing a small number of extra spaces, it will balance them to separate lines. It tries to use the same number of extra spaces to make them balanced.This algorithm will produce how many words can be placed in one line, and how many lines are needed.Input and OutputInput: The length of words for ... Read More

Weighted Job Scheduling

Ankith Reddy
Updated on 17-Jun-2020 07:53:36

1K+ Views

A list of different jobs is given, with the starting time, the ending time and profit of that job are also provided for those jobs. Our task is to find a subset of jobs, where the profit is maximum and no jobs are overlapping each other.In this algorithm, we use a table to store the results of sub-problems and using the results of subproblems, the whole problem can be solved in a bottom-up manner.The time complexity of this algorithm is O(n^2), but we can change it to O(n Log n) by using a binary search method to search con-conflicting jobs.Input ... Read More

Convert Infix to Prefix Expression

Samual Sam
Updated on 17-Jun-2020 07:51:44

7K+ Views

To solve expressions by the computer, we can either convert it in postfix form or to the prefix form. Here we will see how infix expressions are converted to prefix form.At first infix expression is reversed. Note that for reversing the opening and closing parenthesis will also be reversed.for an example: The expression: A + B * (C - D)after reversing the expression will be: ) D – C ( * B + Aso we need to convert opening parenthesis to closing parenthesis and vice versa.After reversing, the expression is converted to postfix form by using infix to postfix algorithm. ... Read More

Advantages and Disadvantages of Arrays in Java

Prabhas
Updated on 17-Jun-2020 07:50:41

2K+ Views

BenefitsEasier access to any element using the index.Easy to manipulate and store large data.DisadvantagesFixed size. Can not be increased or decrease once declared.Can store a single type of primitives only.

Evaluate Postfix Expression

karthikeya Boyini
Updated on 17-Jun-2020 07:45:37

9K+ Views

For solving a mathematical expression, we need prefix or postfix form. After converting infix to postfix, we need postfix evaluation algorithm to find the correct answer.Here also we have to use the stack data structure to solve the postfix expressions.From the postfix expression, when some operands are found, pushed them in the stack. When some operator is found, two items are popped from the stack and the operation is performed in correct sequence. After that, the result is also pushed in the stack for future use. After completing the whole expression, the final result is also stored in the stack ... Read More

Advertisements