0% found this document useful (0 votes)
67 views7 pages

Exp 1: WAP To Print Your Name On Console Output

This document contains 5 Java programming experiments: 1) A program to print a name 2) Programs to calculate the hypotenuse of a triangle using user input or command line arguments 3) A program to convert between Fahrenheit and Celsius temperatures 4) A program demonstrating bitwise operators 5) Programs demonstrating implicit and explicit type conversions in Java

Uploaded by

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

Exp 1: WAP To Print Your Name On Console Output

This document contains 5 Java programming experiments: 1) A program to print a name 2) Programs to calculate the hypotenuse of a triangle using user input or command line arguments 3) A program to convert between Fahrenheit and Celsius temperatures 4) A program demonstrating bitwise operators 5) Programs demonstrating implicit and explicit type conversions in Java

Uploaded by

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

Exp 1: WAP to print your name on console output.

class name
{
public static void main(String args[ ])
{
System.out.println ("Information Technology");
}
}

Output :
Exp 2: (a) Calculate length of hypotenuse of triangle by accepting input from user.

import java.io.*;
class hyp1user
{
public static void main(String args[ ])
{
InputStreamReader istream= new InputStreamReader(System.in);
BufferedReader bufread= new BufferedReader(istream);
System.out.println("hypotenous");
try
{
System.out.println("enter ist side: ");
String s1=bufread.readLine();
System.out.println("enter 2nd side: ");
String s2=bufread.readLine();
int side1=Integer.parseInt(s1);
int side2=Integer.parseInt(s2);
double side3=Math.sqrt((side1*side1)+(side2*side2));
System.out.println("The Hypotenous is:-"+side3);
}
catch(IOException rr)
{
System.out.println("error reading line");
}
catch(NumberFormatException err)
{
System.out.println("error converting");
}
}
}

Output :
(b) using command line arguments.
import java.io.*;
class hypodirect
{
public static void main(String args[ ])
{
int a,b;
double h;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
h=Math.sqrt((a*a)+(b*b));
System.out.println("the hypo is" +h);
}
}

Output :
Exp 3 : conversion of temperature from Fahrenheit to Celsius and vice-versa
import java.io.*;
class te
{
public static void main(String ap[ ])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
double c,f;
System.out.println("Enter temp. in fahrenheit");
f=Double.parseDouble(in.readLine());
c=(f-32)/1.8;
System.out.println("Temp. degree celcious"+c);
System.out.println("Enter temp. in celsius");
f=Double.parseDouble(in.readLine());
c=(f*1.8)+32;
System.out.println("Temp. degree farh."+c);
}
}

output :
Exp 4 : WAP which use of bitwise operators.

import java.io.*;
class ope
{
public static void main(String args[ ])
{
int a=1;
int b=2;
int c=3;
a=a/b;
b=b>>1;
c=c<<1;
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
}
}

output :
Exp 5 : Type conversion : implicit and explicit.

Implicit conversion :

import java.io.*;
class promotion
{
public static void main(String args[ ])
{
byte b=42;
char c='a';
short s=1024;
int i=50000;
float f=5.67f;
double d=.1234;
double result=(f*b)+(i/c)-(d*s);
System.out.println((f*b)+(i/c)+"-"+(d*s));
System.out.println("result"+result);
}
}

output:
Explicit conversion :

import java.io.*;
class explicit
{
public static void main(String args[])
{
byte b;
int i=257;
double d=323.142;
System.out.println("conversion of int to byte ");
b=(byte)i;
System.out.println("i and b " + i + " byte value is : " +b);

System.out.println("conversion of double to int ");


i=(int)d;
System.out.println("a and i " + d + " int value: "+i);

System.out.println("conversion of double to byte ");


b=(byte)d;
System.out.println("d and b " + d + " byte value: "+b);

}
}

output :

You might also like