Programming Articles - Page 2430 of 3363

Program for Volume and Surface Area of Cuboid in C++

Sunidhi Bansal
Updated on 20-Sep-2019 12:36:32

810 Views

What is cuboid?Cuboid is a three-dimensional object with six faces of rectangle shape which means it has sides of different length and breadth. The difference between a cube and cuboid is that a cube has equal length, height and breadth whereas in cuboids these three are not sameProperties of cuboid are −six faces12 edges8 verticesGiven below is the figure of cubeProblemGiven with the length, width and volume, the task is to find the total surface area and volume of a cuboid where surface area is the space occupied by the faces and volume is the space that a shape can ... Read More

Program for Volume and Surface Area of Cube in C++

Sunidhi Bansal
Updated on 20-Sep-2019 12:08:08

934 Views

What is cube?Cube is a three-dimensional object with six faces of square shape which means it has sides of same length and breadth. Cube is the only regular hexahedron with following properties −six faces12 edges8 verticesGiven below is the figure of cubeProblemGiven with the side, the task is to find the total surface area and volume of a cube where surface area is the space occupied by the faces and volume is the space that a shape can contain.To calculate surface area and volume of a cube there is a formula −Surface Area = 6*Side*sideVolume = Side*side*sideExampleInput-: side=3 Output-: volume ... Read More

Program for Surface Area of Octahedron in C++

Sunidhi Bansal
Updated on 20-Sep-2019 12:02:36

230 Views

What is Octahedron?The word ‘dodecahedron’ is derived from the Greek words where, Octa means ‘Eight’ and hedron specifies ‘faces’. octahedron in geometric is a 3-D platonic or regular solid with eight faces. Like, other figures octahedrons also have properties and that are −6 polyhedron vertices12 polyhedron edges8 equilateral facesGiven below is the figure of octahedronProblemGiven with the sides, the program must find the surface area of octahedron where surface area is the total space occupied by the faces of the given figure.To calculate surface area of octahedron there is a formula −Where, a is side of an OctahedronExampleInput-: side=5 Output-: ... Read More

Program for Surface area of Dodecahedron in C++

Sunidhi Bansal
Updated on 20-Sep-2019 11:58:55

255 Views

What is Dodecahedron?The word ‘dodecahedron’ is derived from the Greek words where, dodeca means ‘twelve’ and hedron specifies ‘faces’. Dodecahedron in geometric is a 3-D platonic or regular solid with twelve flat faces. Like, other figures dodecahedron also have properties and those are −20 polyhedron vertices30 polyhedron edges12 pentagonal faces, as a pentagon is a five-sided polygonGiven below is the figure of dodecahedronProblemGiven with an edge, the program must find the surface area of dodecahedron where surface area is the total space occupied by the faces of the given figure.To calculate surface area of dodecahedron there is a formula −ExampleInput-: ... Read More

Program for factorial of a number in C program

Sunidhi Bansal
Updated on 20-Sep-2019 11:53:49

837 Views

Given with the number n the task is to calculate the factorial of a number. Factorial of a number is calculated by multiplying the number with its smallest or equal integer values.Factorial is calculated as −0! = 1 1! = 1 2! = 2X1 = 2 3! = 3X2X1 = 6 4! = 4X3X2X1= 24 5! = 5X4X3X2X1 = 120 . . . N! = n * (n-1) * (n-2) * . . . . . . . . . .*1ExampleInput 1 -: n=5    Output : 120 Input 2 -: n=6    Output : 720There are multiple methods that ... Read More

StringTokenizer methods in Java

AmitDiwan
Updated on 20-Sep-2019 11:32:32

403 Views

The StringTokenizer class allows an application to break a string into tokens. Following are the methods −Sr.NoMethod & Description1int countTokens()This method calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.2boolean hasMoreElements()This method returns the same value as the hasMoreTokens method.3boolean hasMoreTokens()This method tests if there are more tokens available from this tokenizer's string.4Object nextElement()This method returns the same value as the nextToken method, except that its declared return value is Object rather than String.5String nextToken()This method returns the next token from this string tokenizer.6String nextToken(String delim)This method returns the next token in this ... Read More

Traverse through a HashMap in Java

AmitDiwan
Updated on 20-Sep-2019 11:25:42

2K+ Views

To traverse through a HashMap, use Iterator. The HashMap class uses a hashtable to implement the Map interface. This allows the execution time of basic operations, such as get( ) and put( ), to remain constant even for large sets.Following is the code to traverse through a HashMap −Exampleimport java.util.*; public class Main {    public static void main(String args[]) {       HashMap hashMap = new HashMap();       hashMap.put("John", new Integer(10000));       hashMap.put("Tim", new Integer(25000));       hashMap.put("Adam", new Integer(15000));       hashMap.put("Katie", new Integer(30000));       hashMap.put("Jacob", new Integer(45000));   ... Read More

The new operator in Java

AmitDiwan
Updated on 20-Sep-2019 11:23:09

7K+ Views

The new operator is used in Java to create new objects. It can also be used to create an array object.Let us first see the steps when creating an object from a class −Declaration − A variable declaration with a variable name with an object type.Instantiation − The 'new' keyword is used to create the object.Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.Now, let us see an example −Examplepublic class Puppy {    public Puppy(String name) {       // This constructor has one parameter, name.     ... Read More

Nested Classes in Java

AmitDiwan
Updated on 20-Sep-2019 11:09:52

2K+ Views

Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class. Nested classes are divided into two types −Non-static nested classes (Inner Classes) − These are the non-static members of a class.Static nested classes − These are the static members of a class.Following are the types of Nested classes in Java −Non-static nested classes (Inner Classes)Inner classes are a security mechanism in Java. We know a class cannot be associated with the access modifier private, but if we have the class as a ... Read More

Java Integer compareUnsigned() method

AmitDiwan
Updated on 20-Sep-2019 11:06:25

237 Views

The compareUnsigned() method compares two integer objects numerically considering the values as unsigned.The return value if 0 if both values are equal; -1 if the val1is less than val2. The return value is 1, if the val1 is more than val2.At first, set two Integer objects −int val1 = 50; int val2 = -10;Now, compare them considering the values as unsigned −System.out.println(Integer.compareUnsigned(val1, val2));Following is an example to implement the compareUnsigned() method in Java −Examplepublic class Main {    public static void main(String[] args) {       int val1 = 50;       int val2 = -10;     ... Read More

Advertisements