Venkata Sai has Published 72 Answers

Is main method compulsory in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

To compile a program, you doesn’t really need a main method in your program. But, while execution JVM searches for the main method. In the Java the main method is the entry point Whenever you execute a program in Java JVM searches for the main method and starts executing from ... Read More

What are nested interfaces in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you can define an interface.To create an object of this type you need to implement this interface, provide ... Read More

What is instance variable hiding in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

Whenever you inherit a superclass a copy of superclass’s members is created at the subclass and you using its object you can access the superclass members.If the superclass and the subclass have instance variable of same name, if you access it using the subclass object, the instance variables of the ... Read More

What are the default array values in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

In Java arrays are the reference types which stores multiple elements of the same datatype. You can create an array just like an object using the new keyword −type[] reference = new type[10];or, directly using the flower brackets ({}).int [] myArray = {10, 20, 30, 40, 50}When you create instance ... Read More

Java Program to find all angles of a triangle

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

To find the angles of a triangle we can use sin/cosine rules according to cosine rule −cos A = (b^2 + c^2 - a^2)/2bcwhere A, B , C are the vertices and a, b, c are the sides of the given triangle then, angles of the triangle when the sides ... Read More

Java Programs for printing Pyramid Patterns. (of numbers)

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

Following is a Java program which prints a pyramid of numbers.Example Live Demopublic class PrintingPyramids {    public static void main(String args[]){       int n, i, j, k=1;       n = 5;       for(i = 0; i<= n; i++) {          for(j ... Read More

Java program to print a given pattern. (stars)

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

Following is a Java program which prints a pyramid of numbers.Example Live Demopublic class PrintingPyramidStars {    public static void main(String args[]){       int n, i, j;       n = 5;       for(i = 0; i<= n; i++) {          for(j = ... Read More

Java program for Multiplication of Array elements.

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

To find the product of elements of an array.create an empty variable. (product)Initialize it with 1.In a loop traverse through each element (or get each element from user) multiply each element to product.Print the product.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class ProductOfArrayOfElements {    public static void main(String args[]){   ... Read More

Java program to cyclically rotate an array by one.

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

To rotate the contents of an array cyclically −create an empty variable. (temp)save the last element of the array in it.Now, starting from the nth element of the array, replace the current element with the previous element.Store the element in temp in the 1st position.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public ... Read More

Recursive program to find an element in an array linearly.

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

Following is a Java program to find an element in an array linearly.Example Live Demoimport java.util.Scanner; public class SearchingRecursively {    public static boolean searchArray(int[] myArray, int element, int size){       if (size == 0){          return false;       }       if ... Read More

Advertisements