Posts

Showing posts with the label java

'Java' is not recognized as an internal or external command

Right click on  My Computer Select  Properties Select  Advanced System Settings Select  Advanced  tab Select  Environment Variables Select  Path  under  System Variables Click on  Edit  button In Variable value editor paste this at the start of the line C:\Program Files\Java\jdk-10.0.2\bin; Click Ok then Ok again Restart command prompt otherwise it won't see the change to the path variable Type  java -version  in command prompt.

Some facts about java

Image
() - This is called a pair of  Parentheses ;  The  semicolon  or  semi-colon  (;)  "  double   quotation mark https://en.wikipedia.org/wiki/Quotation_mark class first character will be capital. To create an object in java class_name      object_name(as you want)   = new(keyword)    class_name (); To call variables or fields in java object_name.variable_name = value; To refer the variables of another class  first create object of that class and then call it like this object_name.variable_name=input.nextInt(); //remember we are using (.) separator operator in between object and variable name   object_name.fields_name = value; To call methods in java object_name.method_name = value; To call methods from another class first create object of that class for example if the name of the class is Add then we need to create an object  like this  Add object_name(anythin...

Using the pow()-method in Java(power)

Use  Math.pow(double, double) , or statically import  pow  as such: import static java . lang . Math . pow ;

java programs for printing from 1 to 100

*/ 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 2 is divisible by 1 and 2 exactly two times so 2 is prime number. in case of 3, 3 is divisible by 1 but not divisible by 2 and again 3 is divisible by 3 ,so here we can see that 3 is divisible by 1 and 3 exactly two divisible 2 times so 3 is prime. */ import java.io.*; import java.util.*; class Prime1To100{ public static void main(String args[]){   int i,j,num=100,flag; for(i=1;i<=num;i++) {     //when i will be incremented from 1 to 2 flag will be reset to 0 that's why we are initializing flag here.      flag=0;   for(j=1;j<=i;j++) { if(i%j==0) flag++; } if(flag==2) { System.out.println(i+" "); } } } } out-2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53...

java program for finding Area of rectangle and square using constructor overloading

 /*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 arguments and executes that constructor automatically Here Box is constructor. */ //Area of rectangle and square using constructor overloading. import java.io.*; import java.util.*; //Instance variable  of Box. class Box{ double length; double width; //Constructor for rectangle when two parameter are passed (area). Box(double l,double w){ length=l; width=w; } double AreaRectangle(){ return length*width; } //Constructor for square when one value is initialized(area). Box(double l){ length=l; } double AreaSquare(){ return length*length*length; } } //Main class from where program execution begins class Square_Rectangle_Const_Over...

java program to calculate area and volume using constructor

/*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{     double radius;     double height;     Area(double r,double h){         radius=r;         height=h;     }     double area(){         return (2*3.14*radius*height) + (2*3.14*radius*radius);     } } class Area_Vol_Cylin_Const{ public static void main(String args[]){ Vol cylinder=new Vol(7,10); System.out.println("volume of cylinder is "+cylinder.vol()); Area area=new Area(7,10); System.out.p...

java program for printing the sum of the elements inn the array

package array_sum; import java.io.*; import java.util.Scanner;     public static void main(String[] args) {           int num,i,sum=0;         System.out.println("Enter the size of array");         Scanner sc=new Scanner (System.in);         num=sc.nextInt();         int array[]=new int [100];         System.out.println("Enter the elements in the array one by one");         for(i=0;i<num;i++)         {             array[i]=sc.nextInt();         }         System.out.println("The entered element in the array is");         for(i=0;i<num;i++)         {             System.out.println(array[i]);         }         Sy...