You are on page 1of 7

Practical No 5 Practical Name: WAP to Show use of If-else Statement.

import java.io.DataInputStream; class g { public static void main(String args[]) { DataInputStream in= new DataInputStream(System.in); int a=0; try { System.out.println("Enter an integer"); a= Integer.parseInt(in.readLine()); if(a%2==0) { System.out.println("no is even"); } else { System.out.println("no is odd"); }

} catch(Exception e) { } } }

Output

Practical No 6 Practical Name: WAP to Show Type Casting.

class typ { public static void main(String args[]) { System.out.println("****converting double to integer****"); double d=420.5; int d1=(int)d; System.out.println("Double to integer" +d1); System.out.println("****converting float to integer****"); float f=47.5f; int f1=(int)f; System.out.println("Float to interger" +f1); System.out.println("****converting byte to short****"); byte b=50; short y=(short)b; System.out.println("byte to short" +y); } }

Output

Practical No 7 Practical Name: WAP to Show Use of Various Operators.

import java.io.DataInputStream; class op { public static void main(String[] args) { DataInputStream in= new DataInputStream(System.in); int a=0; float b=0.0f; try { System.out.println("Enter 1st no") a= Integer.parseInt(in.readLine()); System.out.println("Enter 2nd no."); b=Float.valueOf(in.readLine()).floatValue(); System.out.println("*************Arithmetic Operators*****************"); System.out.println("addition=" +(a+b)); System.out.println("subtraction=" +(a-b)); System.out.println("Multiplication=" +(a*b));

System.out.println("Divison=" +(a/b)); System.out.println("Moduls=" +(a%b)); System.out.println("*************Relational Operators*****************"); System.out.println("Check is (a>b)=" +(a>b)); System.out.println("Check is (a<b)=" +(a<b)); System.out.println("check is (a<=b)=" +(a<=b)); System.out.println("check is (a>=b)" +(a>=b)); System.out.println("check is (a==b)" +(a==b)); System.out.println("check is (a!=b)" +(a!=b)); System.out.println("*************Logical Operators*****************"); System.out.println("Check is (a>b&&a==b)=" +(a>b&&a==b)); System.out.println("Check is (a>b||a==b)=" +(a>b||a==b)); System.out.println("*************Increment/Decrement Operators*****************"); System.out.println("value after a++" + a++); System.out.println("value after ++a" + ++a); System.out.println("value after a--" + a--); System.out.println("value after a++" + a++); System.out.println("*************Conditional Operator*****************"); int m=5; int f=2; int n=(m>f)?m:f; System.out.println("Condtional Operator" +n);

} catch(Exception e) { System.out.println("Please enter valid input"); } } }

Output

You might also like