Skip to main content

Posts

Programming C Introduction (Variables, Data types, Specifiers, Identifiers) || Programming C Notes Unit 1

Question: What is Psuedo Code ? Psuedo Code:  Pseudocode is a language-agnostic method for describing algorithms using simple English phrases. It's a helpful tool for programmers to develop algorithms without getting bogged down in specific programming language syntax. It allows for a rough design of a solution based on the problem explanation, helping to clarify the logic before diving into coding. With pseudocode, programmers can focus on the problem-solving process rather than the intricacies of coding syntax. The general guidelines for developing pseudocodes are:  Statements should be written in English and should be programming language independent. Steps of the pseudocodes must be understandable. It should be concise. Each instruction should be written in a separate list and each statement in pseudocode should express just one action for the computer. The keywords like READ, PRINT etc should be write in capi- tal letter.  Each set of instruction should written from...

Linear Search // Sequential Search

Linear search ek simple search algorithm hai jo ek array ya list mein kisi specific element ko dhundne ke liye istemal hota hai. Yeh algorithm ek element ko ek ek karke dekhta hai, aur jab woh element mil jaata hai, toh uski position ya index ko return karta hai. Linear search ki khasiyat yeh hai ki yeh kisi bhi array ya list mein kaam karta hai, lekin iska time complexity O(n) hota hai, jahan n array ya list ki length hoti hai, iska matlab yeh hai ki agar aapke paas bada sa array hai toh ismein element dhundne mein jyada time lag sakta hai. Java mein linear search ka ek example niche diya gaya hai: ```java public class LinearSearch {     public static int linearSearch(int[] arr, int key) {         for (int i = 0; i < arr.length; i++) {             if (arr[i] == key) {                 return i; // Element mil gaya, iska index return karo             } ...

Sum On Array

  package HelloWorld ; import java . util . Scanner ; public class SumArray { public static void main ( String [] args ) { Scanner scan = new Scanner ( System . in ) ; //input int size = scan . nextInt () ; int sum = 0 ; int [] sumArray = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { sumArray [ i ] = scan . nextInt () ; sum = sum + sumArray [ i ] ; } //output int Nsize = sumArray . length ; for ( int j = 0 ; j < Nsize ; j ++ ) { } System . out . println ( sum ) ; } }

Input and Output Array using Function

  package HelloWorld ; import java . util . Scanner ; //this is a Scanner class public class LearningJava { /*You have been given a random integer array/list(ARR) of size N, and an integer X. You need to search for the integer X in the given array/list using 'Linear Search'. You have been required to return the index at which X is present in the array/list. If X has multiple occurrences in the array/list, then you need to return the index at which the first occurrence of X would be encountered. In case X is not present in the array/list, then return -1. 'Linear search' is a method for finding an element within an array/list. It sequentially checks each element of the array/list until a match is found or the whole array/list has been searched.*/ public static int [] takeInput () { Scanner scan = new Scanner ( System . in ) ; //input int size = scan . nextInt () ; int [] input = new int [ size ] ; for ( int i = 0 ; i <...

Array Practice Question - - -

Question: Take an array as input from the user. Search for a given number x and print the index at which it occurs. Ans:  package HelloWorld ; import java . util . Scanner ; //this is a Scanner class public class LearningJava { public static void main ( String [] args ) { Scanner scan = new Scanner ( System . in ) ; int size = scan . nextInt () ; int [] numBer = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { numBer [ i ] = scan . nextInt () ; } // int x = scan . nextInt () ; for ( int j = 0 ; j < numBer . length ; j ++ ) { if ( numBer [ j ] == x ) { System . out . println ( "Number Found:" + j ) ; } } } }

Arrays In Java

Question: What is Array in Java ? Ans: java me Array ek Non primitive data type ek data structure hota hai jo multiple variable ko ek sath store krne me help karta hai . Syntax of Array Syntax of Array - - - - type [] arryName = new type[size]; 1) type=  Type ka mtlb hame jis type ka array chahiye jaise int,float, double  2) [ ] = ye square bracket jaha v honge java me iska mtlb hai we are creating a array 3) arrayName = arrayName just like a variable name  4) new = new ek keyword hai, new ka use ham krte hai ek non primite data type ke liye memory me space allocate krne ke liye. Example:  int [ ] studentMarks = new int [ 3 ] ;

Reverse a string on Java

  Write a Java program to reverse a string. Input Data: Input a string: The quick brown fox Expected Output Ans: package learning ; import java . util . Scanner ; public class learnNew { public static void main ( String [] args ){ String word = "The quick brown fox" ; int leng = word . length () ; /// ye java function string ki length btane ke liye use hota hai String rev = "" ; // yaha ham reverse string ko store kr rhe kyo ki koi v variable value change ya replace nhi ho skti for ( int i = leng - 1 ; i >= 0 ; i -- ) { // leng -1 se start kr rhe kyo ki string ki index 0 hoti hai rev = rev + word . charAt ( i ) ; } System . out . println ( rev ) ; } } xof nworb kciuq ehT