0% found this document useful (0 votes)
6 views

operators

Uploaded by

nishita6978
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

operators

Uploaded by

nishita6978
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

package arithematic;

public class Arithematic {

public static void main(String[] args) {

/* for integer values

int a=14,b=5;

int c=a/b;

int r=a%b;

System.out.println(c);

System.out.println(r);*/

/*for float values

float a=14.3f,b=3.2f;

float c=a/b;

float r=a%b;

System.out.println(c);

System.out.println(r);*/

/* for different data types

byte a=10;

short b=15;

int c=a+b;

float a=12.5f;

long b=1231;

float c=a*b;

float a=12.5f;

double b=123;

double c=a*b;

char a=40;

int b=30;

int c=a-b;

System.out.println(c);*/

System.out.println((10+20)/2);

System.out.println(10/(2*5)); } }
package expression;

import java.lang.*;

import java.util.*;

public class Expression {

/* public static void main(String[] args) {

float base,height,area;

System.out.println("Enter Base and Height");

Scanner sc=new Scanner(System.in);

base=sc.nextFloat();

height=sc.nextFloat();

area=base*height*0.5f;

//area=1f/2f*base*height;

//area=base*height/2;

System.out.println("Area of Triangle is "+area);

}*/

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int a,b,c;

double s,area;

System.out.println("Enter 3 Sides of a Triangle");

a=sc.nextInt();

b=sc.nextInt();

c=sc.nextInt();

s=(a+b+c)/2f;

area=Math.sqrt(s*(s-a)*(s-b)*(s-c));

System.out.println("Area of Triangle is "+area);

}
package expression1;

import java.lang.*;

import java.util.*;

public class Expression1 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int a,b,c;

double r1,r2;

System.out.println("Enter the values of a ,b and c");

a=sc.nextInt();

b=sc.nextInt();

c=sc.nextInt();

r1=(-b+Math.sqrt(b*b-4*a*c))/(2*a);

r2=(-b-Math.sqrt(b*b-4*a*c))/(2*a);

System.out.println("Roots are "+r1+" "+r2 );

}
package expression2;

import java.lang.*;

import java.util.*;

public class Expression2 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int length,breadth,height;

int totalArea,volume;

System.out.println("Enter length, breadth and height");

length=sc.nextInt();

breadth=sc.nextInt();

height=sc.nextInt();

totalArea=2*(length*breadth+length*height+breadth*height);

volume=length*breadth*height;

System.out.println("Total Area "+totalArea);

System.out.prinlt("Volume "+volume);

}
package incdec;

public class IncDec {

public static void main(String[] args) {

//float x=3.5f

//char x='A'

//byte x=5

/*int x=5;

x++; //++x

System.out.println(x);*/

/*int x=5,y;

y=x++; //++x

System.out.println(x+" "+y);*/

int x=5,y=4,z;

z=2 * x++ + 3 * ++y;

System.out.println(z);

}
package bitwisedemo;

public class BitwiseDemo {

public static void main(String[] args) {

/*int x=10, y=6,z;

z=x&y;

System.out.println(z);*/

/*int x=0b1010, y=0b0110,z;

z=x|y; //x^y

System.out.println(z);*/

/*int x=0b1000;

int y;

y=x<<1; //x<<2 //x>>1 //x>>2

System.out.println(y);*/

int x=-0b1010; //try with + and -

int y;

y=x>>1; //~x

System.out.println(String.format("%s",Integer.toBinaryString(x)));

System.out.println(String.format("%s",Integer.toBinaryString(y)));

}
package bitwise;

public class Bitwise {

/* public static void main(String[] args) {

int a=10, b=15;

a=a^b;

b=a^b;

a=a^b;

System.out.println(a+ " "+b);

} */

/*public static void main(String[] args) {

byte a=9, b=12;

byte c;

c=(byte)(a<<4);

c=(byte)(c|b);

System.out.println((c&0b11110000)>>4);

System.out.println((c&0b00001111)>>4);

}*/

public static void main(String[] args) {

byte c;

c=(byte)(9<<4);

c=(byte)(c|12);

System.out.println((c&0b11110000)>>4);

System.out.println((c&0b00001111)>>4);

}
package widenarrowdemo;

public class WideNarrowDemo {

public static void main(String[] args) {

byte b=5;

short s=120;

int i=10;

long l=10;

//float f=10;

float f=10.5f;

double d=10;

char c=10;

boolean bl=true;

/*b=(byte)s;

System.out.println(b);

i=s;

l=s;

f=s;

d=s;*/

i=(int)f;

System.out.println(i);

You might also like