Using the pow()-method in Java(power)
Use Math.pow(double, double), or statically import pow as such: import static java.lang.Math.pow;
Use Math.pow(double, double), or statically import pow as such: import static java.lang.Math.pow;
*/ prime number is a number which is divisible by 1 and itself, example 2,3.for printing prime number from 1 to 3 we need to devide 1 by 1 ,2 by 1 and 2 both and 3 by 1,2,and 3. Remember 1 is not considered as prime number. so we will start from 2 so … Read more
/*Area and perimeter of rectangle and square using constructor overloading. Constructor overloading means there will be two or more constructor and the name of all constructors will be same only number of arguments will be different. when you pass arguments value in the constructor it matches the number of arguments value with the defined constructor … Read more
/*Area and perimeter of rectangle and square using constructor overloading. Constructor overloading means there will be two or more constructor and the name of all constructors will be same only number of arguments will be different. when you pass arguments value in the constructor it matches the number of arguments value with the defined constructor … Read more
//Constructor overloading using Box for no parameter for one parameter and for all parameters.import java.io.*;import java.util.*;class MyBox{double length;double depth;double width;//Constructor called when all three dimesions are apecified. MyBox(double l,double d,double w){length = l;depth = d;width = w;}//Defining method to calculate vol.double vol1(){return length*width*depth;}//Constructor when no parameters is initialized.MyBox(){//-1 to indicate an uninitialized box.width=-1;depth=-1;length=-1;}//Defining method to … Read more
//program for box using constructor import java.io.*;import java.util.*; class MyBox{ double length; double breadth; MyBox(double l,double b){ length=l; breadth=b;} double vol(){ return length * breadth; }}class Box{ public static void main(String args[]){ MyBox rectangle=new MyBox(10,20); System.out.println(“vol is “+rectangle.vol());}} OUTPUT-vol is 200.0
/*1 1 0 1 0 11 0 1 01 0 1 0 1*/ import java.io.*;import java.util.*; public class Binary_triangle {public static void main(String[] args) { int num,row,coloumn; System.out.println(“Enter the size of row”); Scanner sc=new Scanner(System.in); num=sc.nextInt(); for(row=1;row<num;row++) { for(coloumn=1;coloumn<=row;coloumn++) System.out.print(coloumn % 2+”t”); System.out.print(“n”); } } }
/*constructor is a special type of method in which the name of the method is same as the class and there is no return type constructor are used to initialize the value of data.*/ //Area and volume of cylinder using constructor.import java.io.*;import java.util.*;class Vol{double radius;double height;Vol(double r,double h){radius = r;height = h;}double vol(){return 3.14*radius*radius*height;}}class Area{ … Read more
package arraysearch;import java.io.*;import java.util.*; public class Arraysearch { public static void main(String[] args) { int num,i,num2,flag=0; System.out.println(“Enter the size of array”); Scanner sc=new Scanner(System.in); num=sc.nextInt(); … Read more
package arraysort;import java.io.*;import java.util.*; public class Arraysort { public static void main(String[] args) { int num,i,j,temp; System.out.println(“Enter the size of array”); Scanner sc=new Scanner(System.in); num=sc.nextInt(); System.out.println(“Enter elements in array one by one”); int array[]=new … Read more