R20 C Syllabus
Regulation | Month & Year | Download File |
---|---|---|
R20 | April -2022-Regular | 4 Sets |
R20 | Dec -2021-Supply | 1 Set |
R20 | AUG -2021-Regular | 1 Set |
R19 | JAN -2020-Regular | 4 Sets |
Associate Professor & HOD,
Department of Information Technology,
Dhanekula Institute of Engineering & Technology
Some PCs might have Java already installed. To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe):
Setup for Windows To install Java on Windows: 1.Go to "System Properties" (Can be found on Control Panel > System and Security > System > Advanced System Settings) 2.Click on the "Environment variables" button under the "Advanced" tab 3.Then, select the "Path" variable in System variables and click on the "Edit" button 4.Click on the "New" button and add the path where Java is installed, followed by \bin. By default, Java is installed in C:\Program Files\Java\jdk-11.0.1 (If nothing else was specified when you installed it). In that case, You will have to add a new path with: C:\Program Files\Java\jdk-11.0.1\bin Then, click "OK", and save the settings 5.At last, open Command Prompt (cmd.exe) and type java -version to see if Java is running on your machine
public class Demoex1 { static Boolean val1; static double val2; static float val3; static int val4; static long val5; static String val6; public static void main (String [] args) { System.out.println("Default values:"); System.out.println("Val1 = " + val1); System.out.println("Val2 = " + val2); System.out.println("Val3 = " + val3); System.out.println("Val4 = " + val4); System.out.println("Val5 = " + val5); System.out.println("Val6 = " + val6); } }
import java. util.*; class Quadratic_qua { public static void main (String [] args) { int a, b, c; double r1, r2, D; Scanner s = new Scanner(System.in); System.out.println("Given quadratic equation:ax^2 + bx + c"); System.out.print("Enter a:"); a = s.nextInt(); System.out.print("Enter b:"); b = s.nextInt(); System.out.print("Enter c:"); c = s.nextInt(); D = b * b - 4 * a * c; if (D > 0) { System.out.println("Roots are real and unequal"); r1 = (- b + Math.sqrt(D))/(2*a); r2 = (-b - Math.sqrt(D))/(2*a); System.out.println("First root is:"+r1); System.out.println("Second root is:"+r2); } else if (D == 0) { System.out.println("Roots are real and equal"); r1 = (-b+Math.sqrt(D))/(2*a); System.out.println("Root:"+r1); } else { System.out.println("Roots are imaginary"); } } }
import java.util.*; class Bikerace { public static void main (String[] args) { float B1,B2,B3,B4,B5,average; Scanner s = new Scanner(System.in); System.out.println("Enter speed of first racer:"); B1 = s.nextFloat(); System.out.println("Enter speed of second racer:"); B2 = s.nextFloat(); System.out.println("Enter speed of third racer:"); B3 = s.nextFloat(); System.out.println("Enter speed of fourth racer:"); B4 = s.nextFloat(); System.out.println("Enter speed of fifth racer:"); B5 = s.nextFloat(); average=(B1+B2+B3+B4+B5)/5; if(B5>average) System.out.println("Fifth racer is qualify racer:"); if(B4>average) System.out.println("Fourth racer is qualify racer:"); if(B3>average) System.out.println("Third racer is qualify racer:"); if(B2>average) System.out.println("Second racer is qualify racer:"); if(B1>average) System.out.println("First racer is qualify racer:"); } }
import java.io.*; import java.util.Scanner; class BinarySearchExample { int binarySearch2a(int arr[], int x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; // Check if x is present at mid if (arr[m] == x) return m; // If x greater, ignore left half if (arr[m] < x) l = m + 1; // If x is smaller, ignore right half else r = m - 1; } return -1; } public static void main(String args[]) { BinarySearchExample ob = new BinarySearchExample(); int arr[ ]=new int[5]; Scanner s = new Scanner(System.in); System.out.println("Enter elements in sorted order:"); for (int i = 0; i < 5; i++) arr[i] = s.nextInt(); System.out.println("Enter the search value:"); int x = s.nextInt(); int result = ob.binarySearch2a(arr, x); if (result == -1) System.out.println("Element is not present in array"); else System.out.println("Element is present at "+ "index " + result); } }
import java.util.Scanner; class Sort{ void Bubsorting(int a[],int n) { int temp,i,j; for(i=0;i<n;i++) { for(j=0;j<n-1;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } System.out.println("The sorted elements are:"); for(i=0;i<n;i++) System.out.print("\t"+a[i]); } } class bubblesort2b{ public static void main(String args[]){ int n, i,j, temp; int a[]=new int[20]; Scanner s = new Scanner(System.in); System.out.println("Enter total number of elements:"); n = s.nextInt(); System.out.println("Enter elements:"); for (i = 0; i < n; i++) a[i] = s.nextInt(); Sort s1=new Sort(); s1.Bubsorting(a,n); } }
import java.util.Scanner; import java.io.IOException; public class Mergesort2c { public static void sort(int[] a, int low, int high) { int N = high - low; if (N <= 1) return; int mid = low + N/2; sort(a, low, mid); sort(a, mid, high); int[] temp = new int[N]; int i = low, j = mid; for (int k = 0; k < N; k++) { if (i == mid) temp[k] = a[j++]; else if (j == high) temp[k] = a[i++]; else if (a[j]<a[i]) temp[k] = a[j++]; else temp[k] = a[i++]; } for (int k = 0; k < N; k++) a[low + k] = temp[k]; } public static void main(String args[]) { Scanner s= new Scanner(System.in); int n, i; System.out.println("Enter number of integer elements"); n = s.nextInt(); int arr[] = new int[ n ]; System.out.println("\nEnter "+ n +" integer elements"); for (i = 0; i < n; i++) arr[i] = s.nextInt(); sort(arr, 0, n); System.out.println("\nElements after sorting "); for (i = 0; i < n; i++) System.out.print(arr[i]+" "); System.out.println(); } }
class stringbuffer2d{ public static void main(String[] args){ StringBuffer sb1 = new StringBuffer("Hello World"); sb1.delete(0,6); System.out.println(sb1); StringBuffer sb2 = new StringBuffer("Some Content"); System.out.println(sb2); sb2.delete(0, sb2.length()); System.out.println(sb2); StringBuffer sb3 = new StringBuffer("Hello World"); sb3.deleteCharAt(0); System.out.println(sb3); } }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Example3a { int a,b,res; BufferedReader br=new BufferedReader(new BufferedReader(new InputStreamReader(System.in))); public void readNumber()throws IOException { System.out.println("enter a value:"); a=Integer.parseInt(br.readLine()); System.out.println("enter b value:"); b=Integer.parseInt(br.readLine()); } public void calculate() { res=a+b; } public void display() { System.out.println("the result is:"+res); } public static void main(String args[])throws IOException { Example3a e=new Example3a(); e.readNumber(); e.calculate(); e.display(); } }
public class VolumeCube { int cube; static double PIE=3.14; VolumeCube(int a) { cube=a*a*a; } public void displayVolume() { System.out.println("the volume of the cube is"+cube); } public static void main(String args[]){ VolumeCube v=new VolumeCube(2); v.displayVolume(); } }
import java.io.IOException; public class Volume4a { static double PIE=3.14; Volume4a(double r,int h) { double cone=(PIE*r*r*h)/3; System.out.println("the volume of cone is "+cone); } Volume4a(double l,double b,double h) { double cuboid=l*b*h; System.out.println("the volume of double cuboid is "+cuboid); } public static void main(String args[])throws IOException { Volume4a v1=new Volume4a(2.5,3); Volume4a v2=new Volume4a(2.2,3.3,4.4); } }
class Adder{ int add(int a,int b){return a+b;} double add(double a, double b){return a+b; } } class Example{ public static void main(String[] args){ Adder A=new Adder(); System.out.println(A.add(5,109)); System.out.println(A.add(7.7,9.2)); } }
import java.util.*; class Data{ protected int a,b; public void readData(){ Scanner sc=new Scanner(System.in); System.out.println("Enter a value"); a=sc.nextInt(); System.out.println("Enter b value"); b=sc.nextInt(); } } class Sum extends Data{ public int c; public void Add(){ c=a+b; System.out.println("Sum of 2 no's is"+c); } } public class singleInherit { public static void main(String[] args) { Sum s=new Sum(); s.readData(); s.Add(); } }
import java.util.*; class A{ public int c; public void Add(int a,int b){ c=a+b; System.out.println("Sum of 2 no's is"+c); } } class B extends A{ public void Diff(int a,int b){ c=a-b; System.out.println("Difference of 2 no's is"+c); } } class C extends B{ public void Mul(int a,int b){ c=a*b; System.out.println("Multiplication of 2 no's is"+c); } } public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter a value"); int a=sc.nextInt(); System.out.println("Enter b value"); int b=sc.nextInt(); C s=new C(); s.Diff(a,b); s.Add(a,b); s.Mul(a,b); } }
import java.util.*; abstract class Areas { abstract void computeArea(); } class areaCircle extends Areas { public double circle,r,pi=3.14; areaCircle(double radius) { this.r=radius; } public void computeArea() { circle=pi*r*r; System.out.print("the area of circle is : "+circle); } } class areaTria extends Areas { public double Traingle,b,h; areaTria(double breadth,double height) { this.b=breadth; this.h=height; } public void computeArea() { Traingle=0.5*b*h; System.out.print("the area of Traingle is : "+Traingle); } } public class areaDemo1 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int ch; Double s,l,b,h,r; while(true) { System.out.print("\n1 : Area of Triangle"); System.out.print("\n2 : Area of circle"); System.out.print("\n3 : Exit"); System.out.print("\nenter your choice"); ch=sc.nextInt(); switch(ch) { case 1: System.out.print("\nEnter breath,height of Triangle"); b=sc.nextDouble(); h=sc.nextDouble(); areaTria ac=new areaTria(b,h); ac.computeArea(); break; case 2: System.out.print("\nEnter radius of circle"); r=sc.nextDouble(); areaCircle aci=new areaCircle(r); aci.computeArea(); break; case 3: System.exit(0); break; default: System.out.println("enter correct choice"); } } } }
class A{ void print(){ System.out.println("A class printing..."); } } class B extends A{ void print(){ System.out.println("B class printing..."); } void work(){ super.print(); print(); } } class TestSuper1{ public static void main(String args[]){ B d=new B(); d.work(); }}
interface FirstInterface { public void myMethod();} interface SecondInterface { public void myOtherMethod();} class DemoClass implements FirstInterface, SecondInterface { public void myMethod() { System.out.println("Some text.."); } public void myOtherMethod() { System.out.println("Some other text..."); } } class Main { public static void main(String[] args) { DemoClass myObj = new DemoClass(); myObj.myMethod(); myObj.myOtherMethod(); }}
public class ExceptionHandling { public static void main(String arg[]) { try { for(int i = -10;i<10;i++) { double d=100/i; System.out.println(d); } } catch(ArithmeticException ae) { System.out.println("Arithmetic Exception is raised."); } finally { System.out.println("This is Finally block"); } } }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; class MultipleCatch { public static void main(String arg[])throws IOException { int a[]=new int[5]; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter element into array"); for(int i=0;i<5;i++) { a[i]=Integer.parseInt(br.readLine()); } try { for(int i=0;i<6;i++) { System.out.println("element:"+a[i]); } } catch(ArithmeticException ae) { System.out.println("Arithmetic Exception is called."); } catch(ArrayIndexOutOfBoundsException aioob) { System.out.println("ArrayIndexOutOfBounds Exception is called."); } finally { System.out.println("This is Finally block"); } } }
class Animal { public void move() { System.out.println("Animals can move"); } } class Dog extends Animal { public void move() { System.out.println("Dogs can walk and run"); } } public class TestDog { public static void main(String args[]) { Animal a = new Animal(); Animal b = new Dog(); a.move(); b.move(); } }
The Above code defines two classes: Animal and Dog. The Animal class is the base class, while the Dog class is a subclass that extends the functionality of the Animal class. This establishes a hierarchical relationship, illustrating the concept of inheritance. The move method in both the Animal and Dog classes demonstrates polymorphism. In Java, polymorphism allows a single method name to be used for methods that have the same name but belong to different classes. This is achieved through method overriding, where a subclass provides a specific implementation of a method defined in its superclass. Animal a = new Animal(); Animal b = new Dog(); a.move(); b.move(); In the above code, a is an instance of the Animal class, and b is an instance of the Dog class. At compile-time, the compiler recognizes the type of the reference variable (Animal), but at runtime, the actual object type (Dog) determines which version of the move method is called. This is known as runtime polymorphism or dynamic method dispatch.
public class Main { static void checkAge(int age) { if (age < 18) { throw new ArithmeticException("You must be at least 18 years old."); } else { System.out.println("You are old enough!"); } } public static void main(String[] args) { checkAge(15); } }
class MyException extends Exception { public MyException(String s) { super(s); } } public class UserDefinedExceptionDemo { public static void main(String args[]) { try { throw new MyException("Dhanekula"); } catch (MyException ex) { System.out.println("Caught the exception1"); System.out.println(ex.getMessage()); } finally { System.out.println("Caught the exception2"); } } }
public class ExceptionHandling { public static void main(String arg[]) { try { for(int i = -2;i<5;i++) { System.out.println(100/i); } } catch(ArithmeticException ae) { System.out.println("Arithmetic Exception is raised."); } finally { System.out.println("This is Finally block"); } } }
class MyException extends Exception { public MyException(String s) { super(s); } } public class UserDefinedExceptionDemo { public static void main(String args[]) { try { throw new MyException("Dhanekula"); } catch (MyException ex) { System.out.println("Caught the exception1"); System.out.println(ex.getMessage()); } } }
class ThreadDemo1 implements Runnable { public void run() { System.out.println("good morning"); } } class ThreadDemo2 implements Runnable { public void run() { System.out.println("hello"); } } class ThreadDemo implements Runnable { public void run() { System.out.println("welcome"); } public static void main(String args[]) { ThreadDemo1 td1=new ThreadDemo1(); ThreadDemo2 td2=new ThreadDemo2(); ThreadDemo td3=new ThreadDemo(); Thread t1=new Thread(td1); Thread t2=new Thread(td2); Thread t3=new Thread(td3); try{ t1.start(); t1.sleep(1000); t2.start(); t2.sleep(2000); t3.start(); t3.sleep(3000); } catch(InterruptedException ie) { System.out.println("not possible"); } } }
class TestDaemon extends Thread{ public void run(){ System.out.println("Name: "+Thread.currentThread().getName()); System.out.println("Daemon: "+Thread.currentThread().isDaemon()); } public static void main(String[] args){ TestDaemon t1=new TestDaemon(); TestDaemon t2=new TestDaemon(); t1.setDaemon(true); t1.start(); try{ t1.join(); //Waiting for t1 to finish } catch(InterruptedException ie){} System.out.println(t1.isAlive()); t2.start(); } }
public class TestDaemon1 extends Thread{ public void run(){ if(Thread.currentThread().isDaemon()){ System.out.println("daemon thread work"); } else{ System.out.println("user thread work"); } } public static void main(String[] args){ TestDaemon1 t1=new TestDaemon1(); TestDaemon1 t2=new TestDaemon1(); t1.setDaemon(true);//now t1 is daemon thread t1.start();//starting threads t2.start(); } }
import java.util.LinkedList; public class PCThreadExample { public static class PC { LinkedListll = new LinkedList<>(); int capacity = 10; public void produce() throws InterruptedException { int values = 0; while(true) { synchronized (this) { while(ll.size() == capacity) { System.out.println("Producer going to wait"); wait(); } System.out.println("Producer Produced ---->"+values); ll.add(values); notify(); values++; Thread.sleep(1000); } } } public void consume() throws InterruptedException { while (true) { synchronized (this) { while (ll.size()==0) { System.out.println("consumer going to wait"); wait(); } int val = ll.removeFirst(); System.out.println("Consumer consumed ---->"+ val); notify(); Thread.sleep(1000); } } } } public static void main(String[] args)throws InterruptedException { final PC pc = new PC(); Thread t1 = new Thread(new Runnable() { @Override public void run() { try { pc.produce(); } catch(InterruptedException e) { e.printStackTrace(); } } }); Thread t2 = new Thread(new Runnable() { @Override public void run() { try { pc.consume(); } catch(InterruptedException e) { e.printStackTrace(); } } }); t2.start(); t1.start(); t1.join(); t2.join(); } }
import java.net.URL; import java.net.URLClassLoader; public class App { public static void main(String[] args) { ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader)sysClassLoader).getURLs(); for(int i=0; i<urls.length; i++) { System.out.println(urls[i].getFile()); } } }
The differences between path and classpath are given by. 1. The PATH is an environment variable used to locate "java" or "javac" command, to run java program and compile java source file. The CLASSPATH is an environment variable used to set path for java classes. 2. In order to set PATH in Java, we need to include bin directory in PATH environment while in order to set CLASSPATH we need to include all directories where we have put either our class file or JAR file, which is required by our Java application. 3. PATH environment variable is used by operating system while CLASSPATH is used by Java ClassLoaders to load class files. 4. Path refers to the system while classpath refers to the Developing Environment. By default the java run time system uses the current working directory. > Normally to execute a java program in any directory we have to set the path by as follows set path= C:\Program Files\java\jdk1.7.0_10\bin: Settings Environmental Variables
package p1; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Addition { //Add two Integers and print the output public void addNumbers() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter first Number: "); float firstNumber = Float.parseFloat(br.readLine()); System.out.print("Enter second Number: "); float secondNumber = Float.parseFloat(br.readLine()); float result = firstNumber + secondNumber; System.out.println("the sum of "+firstNumber+" and "+secondNumber+" is "+result+"."); } } import p1.Addition; import java.io.IOException; public class PackageAddition extends Addition { public static void main(String a[]) throws IOException { PackageAddition a1 = new PackageAddition(); a1.addNumbers(); } }
import java.awt.Graphics; import java.awt.Font; import java.awt.Color; import javax.swing.JApplet; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; public class PaintApplication extends JApplet implements MouseMotionListener { int x=-10,y=-10; String msg=""; public PaintApplication() { addMouseMotionListener(this); } public void mouseDragged(MouseEvent e) { x=e.getX(); y=e.getY(); repaint(); } public void mouseMoved(MouseEvent e) { } public void paint(Graphics g) { Color c = new Color(255,0,0); g.setColor(c); g.fillOval(x,y,25,10); } } /*<applet code="PaintApplication.class" height="400" width="600"> </applet> */
import java.applet.Applet; import java.awt.*; public class GraphicsDemo extends Applet{ public void paint(Graphics g){ g.setColor(Color.red); g.drawString("Welcome",50, 50); g.drawLine(20,30,20,300); g.drawRect(70,100,30,30); g.fillRect(170,100,30,30); g.drawOval(70,200,30,30); g.setColor(Color.pink); g.fillOval(170,200,30,30); g.drawArc(90,150,30,30,30,270); g.fillArc(270,150,30,30,0,180); } } /* <applet code="GraphicsDemo.class" width="300" height="300"> </applet>
import java.applet.*; import java.awt.*; import java.util.*; import java.text.*; public class MyClock extends Applet implements Runnable { int width, height; Thread t = null; boolean threadSuspended; int hours=0, minutes=0, seconds=0; String timeString = ""; public void init() { width = getSize().width; height = getSize().height; setBackground( Color.black ); } public void start() { if ( t == null ) { t = new Thread( this ); t.setPriority( Thread.MIN_PRIORITY ); threadSuspended = false; t.start(); } else { if ( threadSuspended ) { threadSuspended = false; synchronized( this ) { notify(); } } } } public void stop() { threadSuspended = true; } public void run() { try { while (true) { Calendar cal = Calendar.getInstance(); hours = cal.get( Calendar.HOUR_OF_DAY ); if ( hours > 12 ) hours -= 12; minutes = cal.get( Calendar.MINUTE ); seconds = cal.get( Calendar.SECOND ); SimpleDateFormat formatter = new SimpleDateFormat( "hh:mm:ss", Locale.getDefault() ); Date date = cal.getTime(); timeString = formatter.format( date ); // Now the thread checks to see if it should suspend itself if ( threadSuspended ) { synchronized( this ) { while ( threadSuspended ) { wait(); } } } repaint(); t.sleep( 1000 ); // interval specified in milliseconds } } catch (Exception e) { } } void drawHand( double angle, int radius, Graphics g ) { angle -= 0.5 * Math.PI; int x = (int)( radius*Math.cos(angle) ); int y = (int)( radius*Math.sin(angle) ); g.drawLine( width/2, height/2, width/2 + x, height/2 + y ); } void drawWedge( double angle, int radius, Graphics g ) { angle -= 0.5 * Math.PI; int x = (int)( radius*Math.cos(angle) ); int y = (int)( radius*Math.sin(angle) ); angle += 2*Math.PI/3; int x2 = (int)( 5*Math.cos(angle) ); int y2 = (int)( 5*Math.sin(angle) ); angle += 2*Math.PI/3; int x3 = (int)( 5*Math.cos(angle) ); int y3 = (int)( 5*Math.sin(angle) ); g.drawLine( width/2+x2, height/2+y2, width/2 + x, height/2 + y ); g.drawLine( width/2+x3, height/2+y3, width/2 + x, height/2 + y ); g.drawLine( width/2+x2, height/2+y2, width/2 + x3, height/2 + y3 ); } public void paint( Graphics g ) { g.setColor( Color.gray ); drawWedge( 2*Math.PI * hours / 12, width/5, g ); drawWedge( 2*Math.PI * minutes / 60, width/3, g ); drawHand( 2*Math.PI * seconds / 60, width/2, g ); g.setColor( Color.white ); g.drawString( timeString, 10, height-10 ); } } /* <applet code="MyClock.class" width="300" height="300"> </applet> */
import java.awt.Graphics; import java.awt.Font; import java.applet.Applet; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; public class MouseMotionXY extends Applet implements MouseMotionListener { int x=0,y=0; String msg=""; public MouseMotionXY() { addMouseMotionListener(this); } public void mouseDragged(MouseEvent e) { x=e.getX(); y=e.getY(); msg="Mouse Beign Dragged at X:"+x+" Y:"+y; } public void mouseMoved(MouseEvent e) { x=e.getX(); y=e.getY(); msg="Mouse Beign Moved at X:"+x+" Y:"+y; repaint(); } public void paint(Graphics g) { Font f = new Font("arial",Font.BOLD,15); g.setFont(f); g.drawString(msg,x,y); } } /*<applet code="MouseMotionXY.class" height="400" width="600"> </applet>*/
import java.awt.Graphics; import java.awt.Color; import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.applet.Applet; public class Key extends Applet implements KeyListener { int X=20,Y=30; String msg="KeyEvents--->"; public void init() { addKeyListener(this); requestFocus(); setBackground(Color.green); setForeground(Color.blue); } public void paint(Graphics g) { g.drawString(msg,X,Y); } public void keyReleased(KeyEvent k) { showStatus("Key Up"); } public void keyPressed(KeyEvent k) { showStatus("KeyDown"); int key=k.getKeyCode(); switch(key) { case KeyEvent.VK_UP: Y=Y-10; showStatus("Move to Up"); break; case KeyEvent.VK_DOWN: Y=Y+10; showStatus("Move to Down"); break; case KeyEvent.VK_LEFT: X=X-10; showStatus("Move to Left"); break; case KeyEvent.VK_RIGHT: X=X+10; showStatus("Move to Right"); break; } repaint(); } public void keyTyped(KeyEvent k) { msg+=k.getKeyChar(); repaint(); } } /* <applet code="Key" width=300 height=400> </applet> */
Regulation | Month & Year | Download File |
---|---|---|
R20 | August -2022-Regular | 4 Sets |
R20 | March -2022-Supply | 1 Set |
R20 | Sep -2021-Regular | 1 Set |
R19 | March -2021-Regular | 4 Sets |
R16 | Oct/Nov-2017-Regular | 4 Sets |
R16 | Oct/Nov-2018-Regular | 4 Sets |
R16 | May-2018-Supply | 1 Set |
R16 | Oct/Nov-2019-Regular | 4 Sets |
R16 | May-2019-Supply | 1 Set |
R16 | Oct/Nov-2020-Supply | 1 Set |
fo = open("temps.txt") f1= open("ftemps.txt","w+") for i in fo: c=float(i) F=(9*c + (32*5))/5 f1.write(str(F)+"\n") f1.close() fo.close()
class Product: def __init__(self,name,amount,price): self.name=name self.amount=amount self.price=price def get_price(self,number_items): if number_items<10: return self.price*number_items elif 10 <=number_items < 100: return 0.9*self.price*number_items else:return 0.8*self.price*number_items def make_purchase(self, quantity): self.amount -= quantity name, amount, price = 'shoes', 200, 1200 shoes = Product(name, amount, price) q1 = 4 print(f'cost for {q1} {shoes.name} = {shoes.get_price(q1)}') shoes.make_purchase(q1) print(f'remaining stock: {shoes.amount}\n') q2 = 12 print(f'cost for {q2} {shoes.name} = {shoes.get_price(q2)}') shoes.make_purchase(q2) print(f'remaining stock: {shoes.amount}\n') q3 = 112 print(f'cost for {q3} {shoes.name} = {shoes.get_price(q3)}') shoes.make_purchase(q3) print(f'remaining stock: {shoes.amount}\n')
class Time(): # constructor def __init__(self, seconds): self.seconds = seconds # function to convert and return a string of minutes and seconds def convert_to_minutes(self): mins = self.seconds//60 # get the total minutes in the given seconds secs = self.seconds - (mins*60) # get the remaining seconds print("{}:{} minutes".format(self.seconds//60,self.seconds%60)) # return the string of minutes:seconds return "%d:%d minutes" %(mins,secs) # function to convert and return string of hours, minutes, and seconds def convert_to_hours(self): secs = self.seconds hours = secs//3600 # get the total hours in the given seconds secs = secs - (hours*3600) # get the remaining seconds mins = secs//60 # get the total minutes in the remaining seconds secs = secs - (mins*60) # get the remaining seconds print("{:.2f} Hors".format(self.seconds/3600)) # return the string of hours:minutes:seconds return "%d:%d:%d" %(hours,mins,secs) time = Time(365) print(time.convert_to_minutes()) time = Time(4520) print(time.convert_to_hours())
class Converter: def __init__(self, n,name): self.value = n self.name=name def FeettoInches(self): Inches=self.value*12 print("Feet to Inches value is ", Inches) def milestokm(self): km=self.value/0.62137 print("miles to KM is ", km) def FeettoYards(self): Yards= self.value * 0.3333 print("Feet to Yards value is ", Yards) def FeettoMiles(self): Miles= self.value * 0.00018939 print("Feet to Miles value is ", Miles) n=float(input("enter feet/inches/cm/mm/km/miles: ")) x=Converter(n,'inches') x.FeettoInches() x.milestokm() x.FeettoYards() x.FeettoMiles()
class power: def pow1(self, x, n): if x==0 or x==1 or n==1: return x if x==-1: if n%2 ==0: return 1 else: return -1 if n==0: return 1 if n<0: return 1/self.pow1(x,-n) val = self.pow1(x,n//2) if n%2 ==0: return val*val return val*val*x x=power() print(x.pow1(2, -2)) print(x.pow1(3, 5)) print(x.pow1(100, 0))
class py_solution: def reverse_words(self, s): return ' '.join(reversed(s.split())) print(py_solution().reverse_words('hello .py'))
string = "I am a python programmer" words = string.split() words = list(reversed(words)) print(" ".join(words))
from tkinter import * from tkinter.filedialog import * from tkinter.scrolledtext import ScrolledText #lab program 2 type root = Tk() root.title('File dialog') textbox = ScrolledText() textbox.grid() filename=askopenfilename(initialdir='C:\Python_Code\examples',filetypes=[('Text files', '.txt'),('All files', '*')]) s = open(filename).read() textbox.insert(1.0, s) mainloop()
from tkinter import * from tkinter.filedialog import * from tkinter import filedialog from tkinter.scrolledtext import ScrolledText #lab program 1 type master = Tk() master.title('File dialog') textbox = ScrolledText() textbox.grid() def callback(): filename=askopenfilename() s = open(filename).read() textbox.insert(1.0, s) errmsg = 'Error!' bt=Button(text='File Open', command=callback) bt.grid(column=1, row=0) mainloop()
try: x=int(input('Enter a number upto 100: ')) if x > 100: raise ValueError(x) except ValueError: print(x, "is out of allowed range") else: print(x, "is within the allowed range")
try: print('try block') x=int(input("Enter a number:")) y=int(input("Enter another number:")) z=x/y except ZeroDivisionError: print("except ZeroDivisionError block") print("Division by not accepted") else: print("else block") print("Division = ", z) finally: print("finally block") print ("Out of try, except, else and finally blocks." ) Output1: try block Enter a number:100 Enter another number:10 else block Division = 10.0 finally block Out of try, except, else and finally blocks. Output2: try block Enter a number:100 Enter another number:0 except ZeroDivisionError block Division by not accepted finally block Out of try, except, else and finally blocks.
# file handling #1)without using with statement file=open('123.txt','w') file.write('hello world') file.close() #2)with try and finally file=open('123.txt','w') try: file.write('hello world') finally: file.close() #3)using with statement with open('123.txt','w') as file: file.write('hello world')
#include<stdio.h> #include<string.h> void main() { int dayno; char *dayname[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday","Sunday" }; printf("Input Day No : "); scanf("%d",&dayno); switch(dayno) { case 1: printf("%s",dayname[0]); break; case 2: printf("%s",dayname[1]); break; case 3: printf("%s",dayname[2]); break; case 4: printf("%s",dayname[3]); break; case 5: printf("%s",dayname[4]); break; case 6: printf("%s",dayname[5]); break; case 7: printf("%s",dayname[6]); break; default: printf("Invalid day number.\nPlease try again .\n"); break; } getch(); }
weight = float(input("enter ur weight: ")) pound = (2.2 * weight) print("After coverting Kgs into pounds is %0.2f" %pound)
a=int(input("enter value of a: ")) b=int(input("enter value of b: ")) c=int(input("enter value of c: ")) Total = (a+b+c) Average = Total/3 print("sum of three numbers is ", Total) print("Avg of three numbers is ", Average) print("sum of three numbers is %d and Avg of three numbers is %0.2f " %(Total,Average))
for i in range(8,90,3): print(i,end=' ')
username=input("enter ur name") n=int(input("how many no of times to print")) c=1 while c<=n: print("u r name is ",username) c=c+1
n=15 for i in range(0,n): for j in range(0,i+1): print("*",end='') print()
for i in range(1,15): print(i*"*")
import random as ra random_num = ra.randint(1, 10) guess=int(input('Guess a number between 1 and 10 until you get it right :')) while random_num != guess: print("try again ") guess = int(input('Guess a number between 1 and 10 until you get it right : ')) print('Well guessed!')
num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) if abs(num1 - num2) <= 0.001: print("Close") else: print("not close")
vowels = ['A', 'E', 'I', 'o', 'U', 'a', 'e', 'i', 'o', 'u'] a=input("enter word") c=0 for i in a: if(i in vowels): c=c+1 if(c!=0): print("string contains vowels")
a=input("enter string 1: ") b=input("enter string 2: ") #result='' if(len(a)==len(b)): for i in range(len(a)): result=a[i]+b[i] print(result,end='') else: print("please enter equal length strings")
n=int(input()) print("{:,}".format(n))
n=input() l=list(n) print("list is",l) res='' i=0 while(i<len(l)): if l[i]=='(': ind=l.index(')') str=''.join(l[i:ind+1]) res=res+'*'+str i=i+len(str) elif l[i].isalpha(): res=res+'*'+l[i] i=i+1 else: res=res+l[i] i=i+1 print(res)
import random as ra list=[] for i in range(20): list.append(ra.randint(1, 100)) print(list) #print the average of the elements in the list sum=0 for i in range(20): sum=sum+list[i] print("average of all the elements in the list is ", sum/len(list)) #Print the second largest and second smallest entries in the list lar=lar2=small=small2=list[0] for i in list[1:]: if i > lar: lar2 = lar lar = i elif lar2 < i: lar2 = i if i < small: small2 = small small = i elif small2 > i: small2 = i print("Largest element is : ", lar) print("Second Largest element is : ", lar2) print("Smallest element is : ", small) print("Second Smallest element is : ", small2) #Print the even numbers in the list for num in list: if num%2==0: print(num,end=' ') #list comprehension even = [num for num in list if num % 2 != 0] print(even)
x=int(input("enter any number: ")) list1=[] for i in range(1, x + 1): if x % i == 0: list1.append(i) print(list1) #list comprehension list=[i for i in range(1, x + 1) if x % i == 0] print(list)
import random as ra list=[] for i in range(100): list.append(ra.randint(0, 1)) print(list) c=0 maxc=0 for i in list: if i == 0: c += 1 else: if c > maxc: maxc = c c = 0 print("the longest run of zeros",maxc)
list=[1,1,2,3,4,3,0,0] list1=[] for i in list: if i not in list1: list1.append(i) print(list1)
n=float(input("Enter Feet")) list=[] list.append(n*12) list.append(n* 0.33333) list.append(n*0.00018939) list.append(n*304.8,2) list.append(n*30.48) list.append(n/ 3.2808) list.append(n/ 3280.8) print(list) print("0.Convert Feet to Inches") print("1.Convert Feet to Yards") print("2.Convert Feet to Miles") print("3.Convert Feet to millimeters") print("4.Convert Feet to centimeters") print("5.Convert Feet to meters") print("6.Convert Feet to kilometers") op=int(input("Choose Options from Above")) print(list[op])
n=float(input("Enter Feet")) print("1.Convert Feet to Inches") print("2.Convert Feet to Yards") print("3.Convert Feet to Miles") print("4.Convert Feet to millimeters") print("5.Convert Feet to centimeters") print("6.Convert Feet to meters") print("7.Convert Feet to kilometers") op=int(input("Choose Options from Above")) if(op==1): Inches=n*12 print("Feet to Inches value is ", Inches) if(op==2): Yards= n * 0.33333 print("Feet to Yards value is ", Yards) if(op==3): Miles= n * 0.00018939 print("Feet to Miles value is ", Miles) if(op==4): MM= n * 304.8 print("Feet to millimeters value is ", MM) if(op==5): CM= n * 30.48 print("Feet to centimeters value is ", CM) if(op==6): meters= n / 3.2808 print("Feet to meters value is ", round(meters,3)) if(op==7): KM= n / 3280.8 print("Feet to kilometers value is ", KM)
def sum_digits(n): sum=0 while n>0: m=n%10 sum=sum+m n=n//10 return sum n=int(input("enter value: ")) print("sum of digits is: ", sum_digits(n))
def Sum(n): sum = 0 for i in n: sum += int(i) return sum n = input("enter value: ") print("sum of digist is: ",Sum(n))
def first_diff(str1,str2): if str1 == str2: return -1 else: return str1.find(str2) str1=input("enter string 1: ") str2=input("enter string 2: ") print(first_diff(str1,str2))
def number_of_factors(n): list=[i for i in range(1, n + 1) if n % i == 0] return len(list) print("number has %d factors" %number_of_factors(20))
def is_sorted1(list2): c = 0 list1=list2[:] list1.sort() if(list2 != list1): c = 1 if(not c): return True else: return False list2 = [121, 14, 15, 82, 100] print(is_sorted1(list2))
import math #Method 1 def root(x,n): return pow(x,1/n) n=2 x=int(input("enter value")) print("Method 1 using pow ", root(x,n), " Method 2, If n value is 2 only using sqrt function ",math.sqrt(x))
def primes(n): list=[] for num in range(n+1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: list.append(num) return list n=int(input("enter n value: ")) print("list of n prime numbers are :", primes(n))
#Without sort Method def merge(list1,list2): list3=list1+list2 print(list3) for i in range (len(list3)): for j in range(i + 1, len(list3)): if(list3[i] > list3[j]): temp = list3[i] list3[i] = list3[j] list3[j] = temp print(list3) list1=[1,2,3,5,6] list2=[3,5,9,10] merge(list1,list2)
#sort Method def merge(list1,list2): list3=list1+list2 list3.sort() print("After merging two list in sorted order",list3) list1=[1,2,3,5,6] list2=[3,5,9,10] merge(list1,list2)
from itertools import permutations s=input('Enter a word:::') for i in range(2,len(s)): for p in permutations(s,i): print(''.join(p),end=' ')
import re fo = open("sample.txt", "r+") str = fo.read() print ("Read String is : ", str) lst = re.findall('\S+@\S+', str) print(";"+lst[0]+";") fo.close()26 to 34 Programs Click Here
Input Format: The first line of the input contains two numbers separated by a space. Output Format: Print the difference in single line Example: Input: 4 2 Output: 2
Input: 2 5 3 1 Output: 3 8 8 3
Input: 1 2 3 4 5 Output: 5 1
Input: 1 2 3 4 5 6 5 Output: 1 2 4 5 5
Input: 101 Output: YES