DEV Community

Vigneshwaralingam
Vigneshwaralingam

Posted on

Qantler interview Experince

1. Get three numbers and find 2nd maximum

import java.util.Scanner;

public class SecondMax {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int secondMax;
        if ((a >= b && a <= c) || (a <= b && a >= c)) secondMax = a;
        else if ((b >= a && b <= c) || (b <= a && b >= c)) secondMax = b;
        else secondMax = c;

        System.out.println("Second Maximum: " + secondMax);
    }
}
Enter fullscreen mode Exit fullscreen mode

2. Recursion- Find sum of digits of a number using recursion.

import java.util.Scanner;
public class SumDigits {
    public static int sumOfDigits(int n) {
        if (n == 0) return 0;
        return n % 10 + sumOfDigits(n / 10);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = sc.nextInt();
        System.out.println("Sum of digits: " + sumOfDigits(num));
    }
}

Enter fullscreen mode Exit fullscreen mode

3. Get numbers until 'q', sum & count

import java.util.Scanner;

public class SumCount {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum = 0, count = 0;

        while (true) {
            String input = sc.nextLine(); // e.g. 10,w
            String[] parts = input.split(",");
            int number = Integer.parseInt(parts[0]);
            char ch = parts[1].charAt(0);

            sum += number;
            count++;

            if (ch == 'q') break;
        }
        System.out.println("Count: " + count);
        System.out.println("Sum: " + sum);
    }
}
Enter fullscreen mode Exit fullscreen mode

4. Get numbers, validate, print min & max

import java.util.*;

public class MinMaxValidation {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> nums = new ArrayList<>();

        while (true) {
            int n = sc.nextInt();
            if (n < 0) {
                System.out.println("Error: Negative number not allowed");
                continue;
            }
            if (n > 999) {
                System.out.println("Error: Number with more than 3 digits not allowed");
                continue;
            }
            nums.add(n);
            if (nums.size() == 5) break; // stop after 5 numbers for example
        }

        System.out.println("Numbers: " + nums);
        System.out.println("Min: " + Collections.min(nums));
        System.out.println("Max: " + Collections.max(nums));
    }
}
Enter fullscreen mode Exit fullscreen mode

5. Animal, Dog, Human (OOP – method overriding)

class Animal {
    void whoAmI() {
        System.out.println("Animal");
    }
}

class Dog extends Animal {
    @Override
    void whoAmI() {
        System.out.println("Dog");
    }
}

class Human extends Animal {
    @Override
    void whoAmI() {
        System.out.println("Human");
    }
}

public class Test {
    public static void main(String[] args) {
        Animal a = new Animal();
        Animal d = new Dog();
        Animal h = new Human();

        a.whoAmI(); // Animal
        d.whoAmI(); // Dog
        h.whoAmI(); // Human
    }
}
Enter fullscreen mode Exit fullscreen mode

6. Circle radius → diameter & area

import java.util.Scanner;

public class Circle {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();

        double diameter = 2 * r;
        double area = Math.PI * r * r;

        System.out.println("Diameter: " + diameter);
        System.out.println("Area: " + area);
    }
}
Enter fullscreen mode Exit fullscreen mode

7. SQL – Create Tables

CREATE TABLE students (
  id INT PRIMARY KEY,
  name VARCHAR(50),
  gender VARCHAR(10),
  class INT
);

CREATE TABLE marks (
  id INT,
  tamil INT,
  eng INT,
  maths INT,
  science INT,
  history INT,
  FOREIGN KEY (id) REFERENCES students(id)
);

-- Create Students table
CREATE TABLE Students (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    gender VARCHAR(10),
    class INT
);

-- Create Marks table
CREATE TABLE Marks (
    id INT PRIMARY KEY,
    tamil INT,
    eng INT,
    maths INT,
    science INT,
    history INT
);

-- Insert example data
INSERT INTO Students VALUES (1, 'Vicky', 'Male', 10);
INSERT INTO Marks VALUES (1, 45, 50, 60, 55, 48);

-- Total marks per student
SELECT s.id, s.name, 
       (m.tamil + m.eng + m.maths + m.science + m.history) AS total
FROM Students s
JOIN Marks m ON s.id = m.id;

-- Count pass students (class 10, pass mark 40)
SELECT COUNT(*) FROM Students s
JOIN Marks m ON s.id = m.id
WHERE s.class = 10
AND m.tamil>=40 AND m.eng>=40 AND m.maths>=40 AND m.science>=40 AND m.history>=40;

Enter fullscreen mode Exit fullscreen mode

8. SQL – Find total marks of each student

SELECT id, (tamil + eng + maths + science + history) AS total
FROM marks;
Enter fullscreen mode Exit fullscreen mode

9. HTML – Students table

<!DOCTYPE html>
<html>
<head><title>Students Table</title></head>
<body>
<table border="1">
<tr><th>ID</th><th>Name</th><th>Class</th><th>Gender</th></tr>
<tr><td>1</td><td>Vicky</td><td>10</td><td>Male</td></tr>
<tr><td>2</td><td>Malini</td><td>8</td><td>Female</td></tr>
</table>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

10. Validate student marks (HTML + JS)

<!DOCTYPE html>
<html>
<body>
<form onsubmit="return validate()">
  Tamil: <input type="text" id="tamil"><br>
  English: <input type="text" id="eng"><br>
  <button type="submit">Submit</button>
</form>

<script>
function validate() {
  let t = document.getElementById("tamil").value;
  let e = document.getElementById("eng").value;
  if (t === "" || e === "") {
    alert("Fields cannot be empty");
    return false;
  }
  return true;
}
</script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

11. Write user input to file

import java.io.*;
import java.util.Scanner;

public class WriteFile {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        FileWriter fw = new FileWriter("output.txt");

        String data = sc.nextLine();
        fw.write(data);
        fw.close();
    }
}
Enter fullscreen mode Exit fullscreen mode

12. Read file and count line, char, words

import java.io.*;

public class FileReadCount {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("output.txt"));
        int lines=0, words=0, chars=0;
        String line;
        while((line=br.readLine())!=null){
            lines++;
            chars += line.length();
            words += line.split("\\s+").length;
        }
        br.close();
        System.out.println("Lines: "+lines);
        System.out.println("Words: "+words);
        System.out.println("Chars: "+chars);
    }
}
Enter fullscreen mode Exit fullscreen mode

13. Stack class (push, pop, peek)

class Stack {
    int[] arr;
    int top, capacity;

    Stack(int size) {
        arr = new int[size];
        capacity = size;
        top = -1;
    }

    void push(int x) {
        if (top == capacity-1) System.out.println("Overflow");
        else arr[++top] = x;
    }

    int pop() {
        if (top == -1) {
            System.out.println("Underflow");
            return -1;
        }
        return arr[top--];
    }

    int peek() {
        if (top == -1) {
            System.out.println("Empty");
            return -1;
        }
        return arr[top];
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
vigneshwaralingam profile image
Vigneshwaralingam

answer all of them—
1.get the three no from the user and find the 2nd maximum
2.recursion—sum of digits
3.get the no from the user stope when enter the 'q' and sum of no and count of no example
10,w,12,r,34,q
count -3
sum-56
4.get the no from the user
—print all them
— min
—max
—show error if >3 digits
—show error if negative
5.animal,dog,human
—method whoami if animal obj call — "animal"dog,human
—-if animal obj call — "animal"
—-if dog obj call — "dog"
—if human obj call — "human"
6.get the radius of circle from the user and found the diameter and area

7-13 answer minimum 2

7 .,8 .students ,marks table

in students
id | name | male\female |class
some datas

in marks table
id | tamil |eng|maths|science| history
some datas

  1. write a sql commant to create a table both
  2. find the total of each students 3.add new values to both(insert new row) 4.for 10 class - pass mark-40 for 8th class pass mark is 35 count the pass students

9.html page to crete a students table

  1. get the students mark and validate it each fieads should not be empty
  2. get the user input and write them on the file 12.read the file and count of line,char,words
  3. create a class stack data structure and create the methods peek ,pop,push and thiere corresponding logics