Sunday, August 30, 2020

write a python program for arithmetic operations for accepting input dynamcially

 #Python program to do arithmetical operations

num1=input('enter number')

num2=input('enter number')

sum=int(num1)+int(num2)

sub=int(num1)-int(num2)

mul=int(num1)*int(num2)

div=int(num1)/int(num2)

exp=int(num1)**int(num2)



print('sum of  {0} num1 {1} and num2 {2} '.format(sum,num1,num2))

print('subtract of {0} num1 {1}and num2 {2}'.format(sub,num1,num2))

print('multiplication of {0}num1 {1} and num2 {2}'.format(mul,num1,num2))

print('divison of {0} num1 {1}and num2 {2}'.format(div,num1,num2))

print('exp of {0} num1 {1} and num2 {2} '.format(exp,num1,num2))

write a python program for implicit type conversion

 num_int = 123

num_flo = 1.23


num_new = num_int + num_flo


print("datatype of num_int:",type(num_int))

print("datatype of num_flo:",type(num_flo))


print("Value of num_new:",num_new)

print("datatype of num_new:",type(num_new))

write a python program drawing grid

def grid(row, col):

  """version with string concatenation"""

  sep = '\n' + '+---'*col + '+\n'

  return sep + ('|   '*col + '|' + sep)*row


print(grid(3,7))

Write a python program for using relational operator

 x = 10

y = 12


# Output: x > y is False

print('x > y is',x>y)


# Output: x < y is True

print('x < y is',x<y)


# Output: x == y is False

print('x == y is',x==y)


# Output: x != y is True

print('x != y is',x!=y)


# Output: x >= y is False

print('x >= y is',x>=y)


# Output: x <= y is True

print('x <= y is',x<=y)

write a python program for factorial using recursion - check types

 def factorial (n):

    if not isinstance(n, int):

        print('Factorial is only defined for integers.')

        return None

    elif n < 0:

         print('Factorial is not defined for negative integers.')

         return None

    elif n == 0:

         return 1

    else:

         return n * factorial(n-1)

factorial('fred')

factorial(-2)

write pyhton program for print current time

 import datetime

print(datetime.datetime.now())

write python program for drawing cricle using turtle

 import turtle

count = 0

while(count < 360):

    turtle.forward(2)

    turtle.left(1)

    count = count + 1

print("Finished!")

write a python program to draw the polygon

 # import turtle library

import turtle

polygon = turtle.Turtle()

my_num_sides = 6

my_side_length = 70

my_angle = 360.0 / my_num_sides

for i in range(my_num_sides):

     polygon.forward(my_side_length) 

     polygon.right(my_angle) 

turtle.done()

write a python Program drawing triangle shape using turtle

import turtle

turtle.forward(200)

turtle.left(90)

turtle.forward(200)

turtle.left(135)

c =((200**2)+(200**2))**0.5

turtle.forward(c) 

write a python program using turtle - star shape

 import turtle

 my_pen = turtle.Turtle()

 for i in range(50): 

my_pen.forward(50)

 my_pen.right(144) 

turtle.done()

write a pyhton program using turtle to draw shape L

 import turtle             

my_pen = turtle.Turtle()      

my_pen.forward(150)           

my_pen.left(90)               

my_pen.forward(75)

Python Program for while Loop

 def countdown(n):

    while(n>0):

        print(n)

        n=n-1

    print("blast")

countdown(4)

Thursday, August 13, 2020

write a java program for bigdecimal?

 import java.math.*;

class FloatTy 

{

public static void main(String[] args) 

{

float v1=12.3f;

System.out.println(v1);

double v2=12.3;

        System.out.println(v2);

System.out.println("0.1f == 0.1 is " + (0.1f == 0.1));

        System.out.println("0.1f is actually " + new BigDecimal(0.1f));

        System.out.println("0.1 is actually " + new BigDecimal(0.1));

}

}


write a java program for Narrow Type casting - Implicit Type Casting - Reduced Modulo

 class Con12 

{

public static void main(String[] args) 

{

int a=257;

byte b;;

        double c=323.142;

b=(byte)a;

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

b=(byte)c;

  System.out.println("c value is"+c+"b value is"+b);

    


}

}


write a java program for Boolean Variable ?

 class BoolTest {

public static void main(String args[]) {

boolean b;

b = false;

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

b = true;

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

// a boolean value can control the if statement

if(b) System.out.println("This is executed.");

b = false;

if(b) System.out.println("This is not executed.");

// outcome of a relational operator is a boolean value

System.out.println("10 > 9 is " + (10 > 9));

}   }


write a java program for the Simple Inheritance

 class Emp 

{

int bonus =4000;

void showbonus()

{

System.out.println("bonus is"+bonus);

}

}

class pro extends Emp

{

int sal=25000;

}

class p1 extends pro

{

int tot;

public static void main(String[] args) 

{

p1 p =new p1();

      p.tot=p.bonus+p.sal;

   p.showbonus();

System.out.println("total salary is "+p.tot);

}

};

Write a java program for constructor Chaining

 class Myclass //

{

String name;

int rollno;

Myclass()

{

System.out.println("no paramerterized constructor");

}

Myclass(int b)

{

this();

System.out.println("one paramerterized constructor");

}

Myclass(String a,int b)

{

this(10);

System.out.println("two paramerterized constructor");

this.print();

}

void print()

{

System.out.println("constructor is called print method");

}

public static void main(String args[])

{

    Myclass m1=new Myclass("Ramu",511);

}

};

write a java program for Hybrid inheritance

 class Hybri 

{

int bonus=2000,sal=5000;

}

class chlid1 extends Hybri

{

void showchild1()

{

System.out.println("bonus"+bonus+"sal"+sal);

}

};

class chlid2 extends Hybri

{

void showchild2()

{

System.out.println("bonus"+bonus+"sal"+sal);

}

};

class Driver1

{

public static void main(String[] args) 

{

chlid1 c1=new chlid1();

        chlid2 c2=new chlid2();

c1.showchild1();

c2.showchild2();

}

}


super class private varibales can't access in child

 class Priva  //super class private varibales can't access in child

{

int a=10;

private int b=20;

}

class Use extends Priva //chlid

int c=20;

}

class Dri

{


public static void main(String[] args) 

{

Use p1=new Use();

System.out.println("public variable"+p1.a);

       System.out.println("private variable"+p1.b);

      System.out.println("private variable"+p1.c);

}

}


write a java program for character variable increment in java

 class D1 

{

public static void main(String[] args) 

{

char ch='X';

ch++;

System.out.println(ch);

}

}


write a java program for character variable Decrement in java

 class D1 

{

public static void main(String[] args) 

{

char ch='X';

ch--;

System.out.println(ch);

}

}

Print the average of three numbers given by user by creating a class named 'Average' having a method to calculate and print the average.

 class  Average

{

int a=5,b=4,c=3;

float avg;

void calaverage()

{

avg=(a+b+c)/3;

}

void printavg()

{

System.out.println("Average of three varibales"+avg);

}

public static void main(String[] args) 

{

    Average a1=new Average();

     a1.calaverage();

a1.printavg();

}

}


•Write a Java class Book with following features:

 

Write a Java class Book with following features:
Instance variables :
title for the title of book of type String.
author for the author’s name of type String.
price for the book price of type double.
Instance methods:
public void setTitle(String title): Used to set the title of book.
public void setAuthor(String author): Used to set the name of author of book.
public void setPrice(double price): Used to set the price of book.
public String getTitle(): This method returns the title of book.
public String getAuthor(): This method returns the author’s name of book.
Public double getPrice( ): Used to set the price of book.
class Book 
{
String title,author;
double price;
void setTitle(String t)
{
title=t;
}
void setAuthor(String a)
{
author=a;
}
void setPrice(double p)
{
price=p;
}
String getTitle()
{
return title;
}
String getAuthor()
{
return author;
}
double getPrice()
{
return price;
}
public static void main(String[] args) 
{
Book b1=new Book();
b1.setTitle("introduction to java");
b1.setAuthor("Dietiel");
b1.setPrice(550.60);
System.out.println("Book Title   "+ b1.getTitle()+"Author   "+b1.getAuthor()+"Price   "+b1.getPrice());
}
}

Write a Java class Author with following features:

 

Write a Java class Author with following features:
Instance variables :
firstName for the author’s first name of type String.
lastName for the author’s last name of type String.
Instance methods:
public void setFirstName (String firstName): Used to set the first name of author.
public void setLastName (String lastName): Used to set the last name of author.
public String getFirstName(): This method returns the first name of the author.
public String getLastName(): This method returns the last name of the author.


class Author 

{

String firstname,lastname;

void setfirstname(String first)

{

firstname=first;

}

void setlastname(String last)

{

lastname=last;

}

String getfirstname()

{

return firstname;

}

String getlastname()

{

return lastname;

}

public static void main(String[] args) 

{

Author a1=new Author ();

a1.setfirstname("john");

a1.setlastname("k");

System.out.println("FirstName is"+a1.getfirstname()+"Last Nameis"+a1.getlastname());

}

}