Skip to main content

Posts

Showing posts from October, 2023

Basics of Programming In C || Sesion 1 & 2

1) About Variables In programming C. Ans: What is Variable: C programming me, "variables" wo placeholders hote hain jahan par aap data store karte hain. In variables me aap numeric values, characters, strings, aur doosre data ko store kar sakte hain. Variables ke use se aap program me data ko manipulate aur process kar sakte hain. In Simple term Variable kisi v container ka rkha gya name hota hai, Suppose ham apne gharo me Sugar, Masale etc steel ke container me store kar rhe hai aur uske upar ek label lga rhe us label me hamne sugar likh diya to ab ye label jisme sugar likha hai wo likha hua name programming ki terms me Variable kehlata hai .  U can say variable is the name of a Memory. C programming me, aap variables ko declare karte hain, jisme aap unka data type aur naam specify karte hain. Kuch common data types hain: 1. `int`: Integer values (pooray numbers) ko store karne ke liye, jaise `int age = 25;`. 2. `float`: Floating-point values (decimal numbers) ko store karne

Static Keyword in JAVA OOPS

  Solution Description Line 2: static functions cannot use non-static variables. Line 3: Static function cannot call non-static function. Line 4:this or super keyword cannot be used inside a static function. ####price is a final field, thus statement “ b.price = 16 “ is incorrect since we cannot re assign a final variable   Static Keyword: Class level variables hi static variables hote hai

Modifier In JAVA

 

Constructor OOPS in java

What is Constructor ? Ans: Constructor is a special type of method whose name is name is same as per class name. What is Main purpose of use Constructor ? Ans: The main purpose of constructor is initialize the object. Evey java class has a Constructor with default type. A constructor is is automatically called at the time of object creation. a constructor never contain any return-type including voi. 

OOPS Java

package oOps ; import java . util .*; public class StudentUse { public static void main ( String [] args ) { // TODO Auto-generated method stub Scanner scan = new Scanner ( System . in ) ; Student s1 = new Student () ; s1 . name = "Divyanshu" ; s1 . rollNumber = 123 ; Student s2 = new Student () ; System . out . println ( s1 . name ) ; } } Question: What is oops and why to use oops ? Ans: OOPs stands for object oriented programming language, the main purpose of oops is to deal with real world entity using programming language . or memory management . OOPs ek code likhne ka tarika hai OOPs Features : Class - Class ek template hota hai jisme sirf ham logic define krte hai, class koi memory nhi leta hai  object - Kisi ke class ka behaviour object hota hai object memory occupy krta hai. Inheritance - Jitni bar chahe classes ko extend karke reuse kr skte hai. Polymorphism - Ek hi object ka behaviour multiple ho skta hai . E

2d Array

  Here is first square bracket will alocate for rows [] second square bracket will alocate for columns;

Reverse String Wordwise

Question:  Reverse the given string word wise. That is, the last word in given string should come at 1st place, last second word at 2nd place and so on. Individual words should remain as it is. Input format : String in a single line Output format : Word wise reversed string in a single line Constraints : 0 <= |S| <= 10^7 where |S| represents the length of string, S. Sample Input 1: Welcome to Coding Ninjas Sample Output 1: Ninjas Coding to Welcome Ans:  package learningJava ; import java . util .*; /** * This program demonstrates a function to reverse words in a given string. * It takes a string as input and reverses the order of words in the string. */ public class regPract { /** * Reverses the order of words in a given string. * * @param end The ending index of the input string. * @param start The starting index for extracting a word. * @param j An index variable used in loops. * @param input The input string to reverse.

Important algorithm of JAVA(Searching and Sorting)

 Java is a versatile programming language, and it can be used to implement a wide range of algorithms. The importance of an algorithm depends on the specific problem you are trying to solve. However, there are several fundamental algorithms and data structures that are commonly used and considered important in computer science and programming. Here are some of them: 1. **Sorting Algorithms:**    - ** QuickSort :** Efficient divide-and-conquer sorting algorithm.    - ** MergeSort :** Another efficient divide-and-conquer sorting algorithm.    - ** HeapSort :** A comparison-based sorting algorithm using a binary heap.    - ** BubbleSort :** Simple but less efficient sorting algorithm. - ** Selection Sort :**  - ** Insertion Sort :** Simple but less efficient sorting algorithm. 2. ** Searching Algorithms: **    - ** Binary Search: ** Efficient searching in sorted arrays or lists.    - ** Linear Search: ** Simple searching technique for unsorted data. 3. **Data Structures:**    - **Arrays:*

String Palindrome in JAVA

Question:  Given a string, determine if it is a palindrome, considering only alphanumeric characters. Palindrome A palindrome is a word, number, phrase, or other sequences of characters which read the same backwards and forwards.   package learningJava ; import java . util .*; public class regPract { /* Find the maximum and minimum element in an array */ public static boolean checkPalindrome ( String str , String rev ) { if ( str . equals ( rev )) { return true ; } return false ; } public static void main ( String [] args ) { Scanner scan = new Scanner ( System . in ) ; System . out . println ( "Enter String:" ) ; String str = scan . nextLine () ; String rev = "" ; for ( int i = str . length () - 1 ; i >= 0 ; i -- ) { rev = rev + str . charAt ( i ) ; } checkPalindrome ( str , rev ) ; boolean isPalindrome = checkPalindrome ( str , rev ) ;

Strings In Java

Question: What is String in JAVA ? Ans: Java me, "String" ek data type hota hai jo text ko represent karta hai. String ek sequence of characters hoti hai, jaise ki alphabets, numbers, symbols, aur special characters. Java me, String class predefined hoti hai, aur aap iska istemal karke text data ko store, manipulate, aur access kar sakte hain. Strings are non Primitive Data Type. Question: What is .length(); ? Ans: this is to check length of a String . Question: Different between single quote and double quote in String . Ans: Single quote ' ' ['D'] is basically used to store character but double quote is used to store " " ["Divyanshu"] a string basically sequence of character .  Question: How to add, concat a string ? Ans : There is two way to concat or add a string               1) first is to use  Addition (+) arithemetic operator               2) .concat package learningJava ; import java . util .*; public class regPract { /* Find