Professional Documents
Culture Documents
import java.io.*;
class convert
{
public static void main (String[] arg)
{
try
{
int i=Integer.parseInt(arg[0]);
int p =(5 *(i-32))/9;
System.out.println("Temperature in Celsius: "+p);
}
catch(Exception e)
{
System.out.println("error");
}
}
}
Output:
import java.io.*;
class square_root
{
public static void main (String[] arg)
{
try
{
DataInputStream dis1 =new DataInputStream(System.in);
System.out.println("Enter any number: ");
int i=Integer.parseInt(dis1.readLine());
double p =Math.sqrt(i);
System.out.println("Square Root is: "+p);
}
catch(Exception e)
{
System.out.println("error");
}
}
Output:
class digits_sum
{
public static void main (String[] arg)
{
try
{
DataInputStream dis1 =new DataInputStream(System.in);
System.out.println("Enter any number of 4 digits: ");
int j,k,l,m,g;
String i=dis1.readLine();
j=Integer.parseInt(i.substring(0,1));
k=Integer.parseInt(i.substring(1,2));
l=Integer.parseInt(i.substring(2,3));
m=Integer.parseInt(i.substring(3,4));
g=j+k+l+m;
System.out.println("Sum of digits are: "+g);
}
catch(Exception e)
{
System.out.println("error"+e);
}
}
}
Output:
switch (c)
{
case 1:
System.out.println("Sum is:" + (a+b));
break;
case 2:
System.out.println("Minus is:" +(a-b));
break;
case 3:
System.out.println("Division is:" +(a/b));
break;
}
}
}
temp = num;
class OverloadDemo
{
void test()
{
System.out.println("No parameters");
}
void test(int a)
{
System.out.println("Method with a parameter: " + a+" is called");
}
}
class overload
{
public static void main(String args[])
{
OverloadDemo ob = new OverloadDemo();
ob.test();
ob.test(10);
}
}
Output:
class B extends A
{
int k;
B(int a, int b, int c)
{
super(a, b);
k = c;
}
void show()
{
System.out.println("k: " + k);
}
}
class override
{
public static void main(String args[])
{
B subOb = new B(1, 2, 3);
subOb.show(); // this calls show() in B
}
class B extends A
{
int k;
B(int i, int b, int c)
{
super(i, b);
k = c;
}
void show()
{
System.out.println("k: " + k);
}
}
class override
{
public static void main(String args[])
{
B subOb = new B(1, 2, 3);
subOb.show(); // this calls show() in B
}
Output:
Output:
Output:
class chck
{
static int count=0;
chck()
{
count=count+1;
}
chck(int n1)
{
count=count+1;
}
void disp()
{
System.out.println("\nNumber of objects created are: "+count);
}
}
class obj_count
{
public static void main(String ar[])
{
chck obj=new chck();
chck obj1=new chck(8);
obj.disp();
}
}
Output:
Output:
class mul_th
{
public static void main( String arg[])
{
new a().start();
new b().start();
}
}
}
}
Output:
class throw_exe
{
void dis()
{
int x=5, y=1000;
try
{
float z= (float) x/ (float) y;
if(z<0.01)
{
throw new paras("Throw Exception: Number is too small");
}
}
catch(paras e)
{
System.out.println(e.getMessage());
}
}
}
/* PTO */
class throws_exe
{
void dis1() throws ArithmeticException
{
int x=2,y=0,z=x/y;
}
}
class test
{
public static void main(String arg[])
{
throw_exe t1=new throw_exe();
t1.dis();
throws_exe t2 = new throws_exe();
try
{
t2.dis1();
}
catch(Exception e)
{
System.out.println("Throws Exception: "+e);
}
}
}
Output:
Output:
repaint();
}
return true;
}
}
Output:
Output:
11
101
1 0 0 1 */
class prnt
{
public static void main(String ar[])
{
int i,j,k=1;
System.out.println("Floyd's triangle");
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if(j==1 || j==i)
k=1;
else
k=0;
System.out.print(k+" ");
}
System.out.print("\n"); }
}
}
Output:
import java.io.*;
import java.lang.Math;
class series1
{
public static void main(String ar[])
{
double i,x=0,n=0,sum=0;
DataInputStream obj= new DataInputStream(System. in);
try
{
System.out.println("Enter the value of x:");
x=Integer.parseInt(obj.readLine());
System.out.println("Enter the value of n:");
n=Integer.parseInt (obj.readLine ());
}
catch (IOException e)
{
}
}
Output:
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
arr3[i][j]=arr1[i][j]+arr2[i][j];
}
}
System.out.println("result of addition of matrix");
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
System.out.print(" " +arr3[i][j]);
}
catch(Exception e)
{
System.out.print("error");
}
}
}
Output:
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
arr3[i][j]=arr3[i][j]+arr1[i][j]*arr2[j][k];
}
}
}
System.out.println("result of multiplication of matrix");
{
for(i=0;i<2;i++)
catch(Exception e)
{
System.out.print("error");
}
}
}
Output: