Posts

Showing posts from August, 2024

DSA with java

//it is for adt in an array  import java.util.*; class fa {     public static void main(String[] args) {         Scanner scan=new Scanner(System.in);         int []a=new int[100];         int n,i;     System.out.println("Enter no of elemnts in an array below 100:");         n=scan.nextInt();         System.out.println("Enter no of elements: ");         for (i=0;i<n;i++){             a[i]=scan.nextInt();         }         scan.close();             } } //insertion at particular index // Online Java Compiler // Use this editor to write, compile and run your Java code online import java .util. * ; public class Array {     public static void main(String[] args) {         int[] a = new int[ 100 ];     ...

umar single linked list

 public class SLL {     class Node {         int data;         Node next;         public Node(int data) {             this.data = data;             this.next = null;         }     }     public Node head = null;       public Node tail = null;     public void insert(int data) {         Node newNode = new Node(data);         if (head == null) {             head = newNode;             tail = newNode;         } else {             tail.next = newNode;             tail = newNode;         }     }     public void insertAtBeginning(int data) {         Node new...

hacker rank py

 if __name__ == '__main__':     n = int(input())     student_marks = {}              for _ in range(n):         name, *line = input().split()         scores = list(map(float, line))         student_marks[name] = scores     query_name = input()     for name in student_marks:         if name==query_name:             a=student_marks[name]             print(format(sum(a)/len(a),'.2f')) #o/p is: 2 faizan 20 20 umar 30 20 faizan 20.00 #sunday: def print_full_name(first_name, last_name):     # Write your code here         print (f 'Hello {first_name} {last_name}! You just delved into python.' ) if __name__ == '__main__' :     first_name = input ()     last_name = input ()     print_full_name(first_name, last_name) #...

unsolved py

if __name__ == '__main__':     N = int(input())     list=[] for i in range(N):     cd=input().split()     if cd[0] == 'insert':         list.insert(int(cd[1]),int (cd[2]))     elif cd[0] == 'print':        print(list)     elif cd[0] =='remove':         list.remove(int(cd[1]))     elif cd[0] =='append':         list.append(int(cd[1]))     elif cd[0]=='sort':         list.sort()     elif cd[0]=='pop':         list.pop()     elif cd[0]=='reverse':         list.reverse()                    #o/p is: #prime number for three inputs: num_a = int(input("Enter a number:")) num_b = int(input("Enter second number:")) num_c = int(input("Enter third number:")) if num_a <= 1 or num_b <= 1 or num_c <= 1: ...

java 1

 //Program For vote criteria: import java.util.*; class HelloWorld {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);         System.out.print("Enter name:");         String name =scan.nextLine();         System.out.print("Enter age:");         int age = scan.nextInt();         if (age>=18){             System.out.println("You are elgible to vote"+" "+name);         }         else{             System.out.println("You are not eligible to vote"+" "+name);         }     } }  //o/p is: Enter name:faizan Enter age:18 You are elgible to vote: faizan \\ public and static method: public class fa{     static void method(){         System.out.println("faiza...

special py

#Takes input from the user and give vowels: try :     name = input ( "Enter name:" )     vowel = 'aeiouAEIOU'     if not name . isalpha ():         raise ValueError ( 'You should enter letters only' )     print ( 'vowels are:' , end = '' )           except ValueError as e :     print ( f "Error: { e } " ) for a in name :     if a in vowel :         print ( a , end = '' ) #o/p is: Enter name:faizan vowels are:aia #unique code by functions: def first ():   return " faizan is great " def second ( self ):   return ' %s faizan codes in python ' % self def third ():     ed = first ()   for a in ed :     print ( second ( a )) third ()   #o/p is: faizan codes in python  f faizan codes in python  a faizan codes in python  i faizan codes in python  z faizan codes in python  a faizan cod...

py2

#switch case  def fa ( story ):   match story :     case 1 :       return "first one"     case 2 :       return "secod one"     case 3 :       return "third one"     case _:       return 'unknown one' print ( fa ( 1 )) print ( fa ( 2 )) print ( fa ( 3 )) print ( fa ( 4 )) #o/p is: first one secod one third one unknown one #try and catch method: try :   first = int ( input ( 'Enter a number:' )) except Exception as e :   print ( f 'you should enter numbers only { e } ' ) print ( 'thanks for your input' ) #unique way  try :   a = int ( input ( "Enter first number:" ))   b = int ( input ( "Enter second number:" )) except Exception as e :     print ( f 'you should enter numberss only' ) if ( b == 0 ):   raise ZeroDivisionError ( 'program is not created for divison by zero' ) print ( f 'your divison is: { a / b } ' ) #addin...