التخطي إلى المحتوى الرئيسي

Most Important Logical Interview Question in 2025 | Solve these question and answer on comment box

 Most Important Logical Interview Question | Solve these question and answer on comment box



1) Write a program to store five product information in object and display max price product details where product contains product id, ProductName, product price.


2) Write a program to split prime and non prime element separately from one dimensional array?


3) Write a program to find max word in paragraph?


4) Write a program to manage possible inheritance between Customer, Product and Order class, where customer contain name and id, product contain name,id,price,and order contain id,name,orderdate?


5) Write a program to calculate addition of two number but input data will be read from file and output data should also write on another file.


تعليقات

  1. 1) Write a program to store five product information in object and display max price product details where product contains product id, ProductName, product price.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace shivaconcepttext
    {
    internal class product_Information
    {
    private int product_id;
    private string product_name;
    internal int product_price;

    internal void accept_information(int product_id,string product_name,int product_price)
    {
    this.product_id = product_id;
    this.product_name = product_name;
    this.product_price = product_price;
    }

    internal void diplay_information()
    {
    Console.WriteLine("id : {0} name : {1} price : {2}",product_id,product_name,product_price);
    }

    public static void Main()
    {
    product_Information[] info = new product_Information[2];
    for (int i = 0; i < info.Length; i++)
    {
    info[i] = new product_Information();
    Console.WriteLine("enter id");
    int id = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("Enter name");
    string name = Console.ReadLine();
    Console.WriteLine("enter price");
    int price = Convert.ToInt32(Console.ReadLine());
    info[i].accept_information(id, name, price);
    }

    int max = 0;
    for (int i = 0; i < info.Length; i++)
    {
    if (max < info[i].product_price)
    {
    max = info[i].product_price;
    }
    }
    Console.WriteLine("max price : " + max);
    }
    }
    }

    ردحذف
  2. Write a program to calculate addition of two number but input data will be read from file and output data should also write on another file.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace shivaconcepttext
    {
    internal class file_aditiontwonumber
    {
    string file = "d://aditionfile.txt";
    int num1, num2;
    internal void createfile()
    {
    if (File.Exists(file))
    {
    Console.WriteLine("file already created");
    }
    else
    {
    FileStream fs = File.Create(file);
    fs.Close();
    Console.WriteLine("file created");
    }
    }

    internal void addcontent()
    {
    StreamWriter sw = new StreamWriter(file);
    if (File.Exists(file))
    {
    Console.WriteLine("enter number first");
    num1 = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("enter number second");
    num2 = Convert.ToInt32(Console.ReadLine());
    sw.WriteLine("first number is : " + num1);
    sw.WriteLine("second number id :" + num2);
    sw.Close();
    Console.WriteLine("number save succesfully");
    }
    else
    {
    Console.WriteLine("file not found");
    }
    }

    internal void readresult()
    {
    StreamReader sr = new StreamReader(file);
    if (File.Exists(file))
    {
    int sum = num1+ num2;
    Console.WriteLine("sum of num1 and num2 : " + sum);
    }
    else
    {
    Console.WriteLine("file not found");
    }
    }
    static void Main(string[] args)
    {
    file_aditiontwonumber obj = new file_aditiontwonumber();
    obj.createfile();
    obj.addcontent();
    obj.readresult();

    }
    }
    }



    ردحذف
  3. Write a program to manage possible inheritance between Customer, Product and Order class, where customer contain name and id, product contain name,id,price,and order contain id,name,orderdate?

    customer class : -

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace shivaconcepttext
    {
    internal class customer_inharitance
    {
    internal int id { get; set; }
    internal string name { get; set; }

    internal void accept_customer()
    {
    this.id = id;
    this.name = name;
    }

    internal void display_customer()
    {
    Console.WriteLine("id : {0} name : {1} price : {2}", id, name);
    }
    }
    }


    product class : -

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml.Linq;

    namespace shivaconcepttext
    {
    internal class product_inharitance : customer_inharitance
    {
    internal string price { get; set; }

    internal void accept_product()
    {
    this.price = price;
    }

    internal void display_product()
    {
    Console.WriteLine("id : {0} name : {1} price : {2}", id, name, price);
    }
    }
    }


    order class : -

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace shivaconcepttext
    {
    internal class order_inharitance : customer_inharitance
    {
    public string OrderDate { get; set; }

    internal void accept_order()
    {
    this.OrderDate = OrderDate;
    }

    internal void display_order()
    {
    Console.WriteLine("id : {0} name : {1} price : {2}", id, name, OrderDate);
    }
    }
    }

    display product class output : -

    static void Main(string[] args)
    {
    product_inharitance obj = new product_inharitance();
    obj.id = 1;
    obj.name = "vaishu";
    obj.price = "45000";
    obj.accept_product();
    obj.display_product();
    }

    ردحذف
  4. //-------------------------
    // Main
    //-------------------------

    namespace SurpriseTest
    {
    internal class Program
    {
    static void Main(string[] args)
    {
    Program1.RunProgram1(); // Run for solutuon to problem 1
    Program2.RunProgram2(); // Run for solutuon to problem 2
    Program3.RunProgram3(); // Run for solutuon to problem 3
    Program4.RunProgram4(); // Run for solutuon to problem 4
    Program5.RunProgram5(); // Run for solutuon to problem 5
    }
    }
    }

    //-------------------------
    // Problem 1
    //-------------------------

    namespace SurpriseTest
    {
    internal class Product
    {
    public int ProductID { get; set; }
    public string? ProductName { get; set; }
    public int ProductPrice { get; set; }
    public void DisplayProductDetails()
    {
    Console.WriteLine("Product ID : " + ProductID);
    Console.WriteLine("Product Name : " + ProductName);
    Console.WriteLine("Product Price : " + ProductPrice);
    }
    }

    internal class Program1
    {
    public static void ProductProgram()
    {
    Product[] productList = new Product[5]
    {
    new Product{
    ProductID = 101,
    ProductName = "Bat",
    ProductPrice = 2300
    },
    new Product{
    ProductID = 102,
    ProductName = "Ball",
    ProductPrice = 3000
    },
    new Product{
    ProductID = 103,
    ProductName = "Pad",
    ProductPrice = 1800
    },
    new Product{
    ProductID = 104,
    ProductName = "Gloves",
    ProductPrice = 1100
    },
    new Product{
    ProductID = 105,
    ProductName = "Helmet",
    ProductPrice = 2000
    },
    };
    Product maxPricePoduct = productList[0];
    for (int i = 1; i < productList.Length; i++)
    {
    if (productList[i].ProductPrice > maxPricePoduct.ProductPrice)
    {
    maxPricePoduct = productList[i];
    }
    }
    Console.WriteLine("Maximum priced product is:-");
    maxPricePoduct.DisplayProductDetails();
    }
    }
    }

    ردحذف
  5. //-------------------------
    // Problem 2
    //-------------------------

    namespace SurpriseTest
    {
    internal class Program2
    {
    static int[] numArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
    public static void RunProg()
    {
    int primeCount = 0;
    int nonPrimeCount = 0;
    int[] primeArray = new int[numArray.Length];
    int[] nonPrimeArray = new int[numArray.Length];
    foreach (int num in numArray)
    {
    bool isPrime = true;
    if (num <= 1)
    {
    isPrime = false;
    }
    else if (num == 2)
    {
    isPrime = true;
    }
    else if (num % 2 == 0)
    {
    isPrime = false;
    }
    else
    {
    int div = 3;
    while (div <= num / 2)
    {
    if (num % div == 0)
    {
    isPrime = false;
    break;
    }
    div += 2;
    }
    }
    if (isPrime)
    {
    primeArray[primeCount++] = num;
    }
    else
    {
    nonPrimeArray[nonPrimeCount++] = num;
    }
    }
    Console.Write("\nPrime Array: ");
    for (int i = 0; i < primeCount; i++)
    {
    Console.Write(primeArray[i] + " ");
    }
    Console.Write("\nNon-Prime Array: ");
    for (int i = 0; i < nonPrimeCount; i++)
    {
    Console.Write(nonPrimeArray[i] + " ");
    }
    }
    }
    }

    //-------------------------
    // Problem 3
    //-------------------------

    namespace SurpriseTest
    {
    internal class Program3
    {
    static string sampleParagraph = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus facilis repudiandae sapiente placeat nobis ut vel ipsam quae dolorum pariatur consectetur magnam blanditiis odit sunt quibusdam eum ullam dolore reprehenderit, et laudantium quo corrupti. Ullam sed quidem cumque ad iusto, quod rerum distinctio magnam odit explicabo cupiditate deleniti repudiandae hic vitae officiis accusantium nulla veritatis molestiae minima. Dolore, soluta minus! Nisi quam animi omnis ex itaque eveniet corporis odio voluptatum iure molestias deserunt saepe hic id, provident magnam molestiae tempore architecto quasi, nam eligendi veniam cupiditate cumque possimus ut? Possimus enim consequuntur, tempore corrupti doloremque tenetur provident, beatae recusandae ad libero praesentium, error rerum repellendus labore deleniti.
    Placeat sapiente maiores magni illo labore provident doloremque distinctio vel dolorem rerum. Molestias, tenetur accusamus? Recusandae atque magnam, at similique quidem in nisi molestias, nulla sunt, rem natus doloribus possimus aliquam maiores! Veritatis exercitationem magnam, dicta necessitatibus voluptatibus laboriosam ex cupiditate asperiores tenetur!";
    public static void RunProgram3()
    {
    string[] wordsOfParagraph = sampleParagraph.Split(' ', ',', '.', '!');
    string longestWord = wordsOfParagraph[0];
    foreach (string str in wordsOfParagraph)
    {
    if (str.Length > longestWord.Length)
    {
    longestWord = str;
    }
    }
    Console.WriteLine("Longest Word is " + longestWord + " & it's length is " + longestWord.Length);
    }
    }
    }

    ردحذف
  6. //-------------------------
    // Problem 4
    //-------------------------

    namespace SurpriseTest
    {
    internal interface ICustomer
    {
    int CustomerId { get; set; }
    string? Name { get; set; }
    }

    internal interface IProduct
    {
    int ProductId { get; set; }
    string? ProductName { get; set; }
    int ProductPrice { get; set; }
    }

    internal interface IOrder : ICustomer,IProduct
    {
    public int OrderId { get; set; }
    public DateTime? OrderDateTime { get; set; }
    public void DisplayOrderDetails();
    }

    internal class Order : IOrder
    {
    public int OrderId { get; set; }
    public DateTime? OrderDateTime { get; set; }
    public int CustomerId { get; set; }
    public string? Name { get; set; }
    public int ProductId { get; set; }
    public string? ProductName { get; set; }
    public int ProductPrice { get; set; }

    public void DisplayOrderDetails()
    {
    Console.WriteLine("\nOrder Details Page");
    Console.WriteLine("Order # : " + OrderId);
    Console.WriteLine("Order Date : " + DateAndTime.DateString);
    Console.WriteLine("Order Time : " + DateAndTime.TimeString);
    Console.WriteLine("Customer Id : " + CustomerId);
    Console.WriteLine("Customer Name: " + Name);
    Console.WriteLine("Product Id : " + ProductId);
    Console.WriteLine("Product Name : " + ProductName);
    Console.WriteLine("Product Price: " + ProductPrice);
    }
    }

    internal class Program4
    {
    internal static void RunProgram4()
    {
    IOrder order1 = new Order()
    {
    OrderId = 1010,
    OrderDateTime = DateTime.Now,
    CustomerId = 1,
    Name = "Virat Kohli",
    ProductId = 5001,
    ProductName = "MRF Genius Grand Edition",
    ProductPrice = 95000
    };
    order1.DisplayOrderDetails();
    }
    }
    }

    //-------------------------
    // Problem 5
    //-------------------------

    namespace SurpriseTest
    {
    internal class Program5
    {
    internal static void RunProgram5()
    {
    string inputFile = @"D:\temp\textDocs\inputNumbers.txt";
    string outputFile = @"D:\temp\textDocs\outputResult.txt";
    int num1 = 0, num2 = 0, result;
    if (!File.Exists(inputFile))
    {
    try
    {
    FileStream fs = File.Create(inputFile);
    fs.Close();
    StreamWriter streamWriter = new StreamWriter(fs.Name);
    streamWriter.Write("10 20");
    streamWriter.Close();
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    }
    try
    {
    StreamReader streamReader = new StreamReader(inputFile);
    string[] texts = streamReader.ReadToEnd().Split(' ', ',');
    streamReader.Close();
    num1 = Convert.ToInt32(texts[0]);
    num2 = Convert.ToInt32(texts[1]);
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    result = num1 + num2;
    try
    {
    StreamWriter streamWriter = new StreamWriter(outputFile);
    streamWriter.WriteLine(result);
    streamWriter.Close();
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    }
    }
    }

    ردحذف

إرسال تعليق

POST Answer of Questions and ASK to Doubt

المشاركات الشائعة من هذه المدونة

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...