examples – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Thu, 14 Mar 2024 16:44:01 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg examples – Programmerbay https://programmerbay.com 32 32 Counting Figures Tricks with Triangle Examples https://programmerbay.com/counting-figures-problem-tricks/ https://programmerbay.com/counting-figures-problem-tricks/#respond Tue, 12 Mar 2024 06:09:49 +0000 https://www.programmerbay.com/?p=4385 Counting figures problems come under non-verbal reasoning in which one is required to identify the exact count of a shape formed within a design or picture like a circle, square, triangle and more. Such type of logical reasoning questions are frequently asked in different aptitude exams.

Counting figures sometimes sound too difficult if you don’t have an idea of how to solve them. In this article, we will be talking about tricks for counting figures problem.

counting figures

These are most repeatedly asked reasoning questions. In this, a shape or a figure would be given to you and your task is to determine the shape and count it down within that particular shape.
For example, consider the below figure:

countinng figure 4

They simply ask in the question, how many triangles are visible in the given figure? Initially, it might look easy but it is obviously not! Without knowing tricks you can’t easily figure out correct answer.

 

Types of questions with Triangle Counting Problem Examples

  • When a triangle  is divided  by  vertical lines

    • In such a case, we use can n (n+1)/2 where n is the number of triangles inside the main triangle

Q.  Find the number of triangles in the diagram

counting figures 1

Number of  triangles  inside the  main triangle   =   4

4(4+1)/2

= 20/2    =    10

 

  •  When a  triangle divided  by the horizontal lines

    • In such a case, count the number of horizontal lines that would give you the total number of triangles

Q.  Find the number  of figures  in the diagram

counting figure 2

Total number of horizontal lines = 3

So total possible triangles are 3

 

  • When a triangle has both vertical and horizontal lines

    • n(n+2)/2 (for vertical lines ) * number of horizontal lines

Q.  Find the number  of triangles in the diagram

counting figures 3

Number of triangles from vertical lines (ignoring horizontal lines) = 3 = 3(3+1)/2 = 6

Horizontal lines  = 3

= 6* 3

= 18

 

  • When a triangle has an inner triangle touching all of the edges of the outer one

    • In such a case, there always 4 figures are made and add 1 for the main triangle

Q.  Find the number  of triangles in the diagram

countinng figure 4

Starting from inner combination there are  = 4 triangle

count me

outer combination there are  = 4 triangle

count me 1

And for main  = 1

total = 9 triangles

 

  • When a triangle has a triangle touching all of the edges of outer one and also has lines from each vertex of the main triangle touching edges of the inner one

    • In this first, ignore all the lines coming from corners of the triangle
    • Now the triangle you see would  be similar to the previous case triangle ( touching all the edges of outer triangle)
    • Count the number of triangles
    • After that consider lines coming from edges, each line would make 2 triangles
    • Now add them all together

counting figure 5

Step 1.  If we ignore the lines coming from edges, the figure would look like

countinng figure 4

Step 2.  From the inner triangle, we will get 4, from outer one = 4, Main triangle = 1

Step 3. Total triangles = 9

Step 4. Now add lines which were removed previously, if each line creates 2 triangles then 3 lines would create = 3*2 =6 triangle

Step 5. Add them all. 9 + 6 = 15 triangles

 

  •  When a triangle has multiple triangles made on horizontal lines 

    • If you look closely from every edge there would equal number of triangles
    • Count triangles from the base
    • Add them in a consecutive manner where the result of the previous one would be used as input for the next one. i.e 1 , 1 +2 = 3, 3+3=6, 4+6 =10′. Add all the sums together.
    • Now after adding them all up, also consider second last sum again
    • Also add it

counting figure 6

Number triangles in each base = 3

Make a counting from 1 to 3

count me 3

Add them up = 1 + 3 + 6 = 10

Now also consider second last item = 3

Total triangle 10 + 3 = 13

 

Counting Figures Practice Questions

 

1. How many triangles are there in the given figure?

Screenshot from 2024 03 14 22 03 30

2. How many triangles are there in the given figure?

Screenshot from 2024 03 14 22 04 34

3.  Find the number of triangles in the given figure :

Screenshot from 2024 03 14 22 08 35

Frequently Asked Questions:

What is the Figure Counting Reasoning?

It comes under non verbal reasoning section where one requires to identify and count the exact number of shapes present in the given figure or design.

]]>
https://programmerbay.com/counting-figures-problem-tricks/feed/ 0
What is Java Interface with examples https://programmerbay.com/what-is-java-interface-with-examples/ https://programmerbay.com/what-is-java-interface-with-examples/#respond Sat, 14 Sep 2019 17:28:58 +0000 https://programmerbay.com/?p=5112 An interface may consist of constants, default methods, abstract methods (without body )and static methods. It explains what a class should do and look like, but not how. It can be extended by other interfaces using ‘ extends’ and implemented by other classes using ‘implements’ keyword.
It cannot be instantiated, further, the class that implements it must provide the body for the implemented abstract method, otherwise, compiler triggers an error. An interface is followed by ‘interface’ keyword.

  • Java doesn’t provide support for multiple inheritance, but it is possible between Interfaces.
  • An interface can have an object, but it can’t be instantiated.
  • It doesn’t allow constructors.
  • It can be extended by other interfaces using ‘extends’ keyword.
  • It can be implemented by other classes using ‘implements’ keyword.

If no modifier is mentioned, then the interface would only be accessed within a package.

Interface having method signatures

In an interface, you can define an abstract method, and that method must be overridden by the class that implements it. In other words, A class which implements an interface must define the body of that abstract method.

Program:

interface Quadilateral{
void area(); // abstract method
}
class rectangle implements Quadilateral{
int length;
int breadth;
@Override
public void area(){
System.out.println("Area of rectangle = "+(length*breadth)+" cm sq.");
}

}
class square{}
public class InterfaceExample {

public static void main(String[] args) {
rectangle obj =new rectangle();
obj.length =10;
obj.breadth=5;
obj.area();
}

}

Output:

interace abstract
void area();

By default, a compiler treats a method within an interface like this:

// abstract returnType methodName();
abstract void area();

Interface having constant

Interface also allow us to declare constants whose declaration and initialization takes place at a single statement.

Program:

interface Pie{
// Compiler would see this statement as public static final double =3.14;
double pie =3.14; // Constant
}
class Showing implements Pie{
void print(){
System.out.println(" I am Printing constant value "+pie);
}
}
public class InterfaceConstant {
public static void main(String[] args) {
Showing obj =new Showing();
obj.print();
}

}

Output:

constant
double pie =3.14;

By default, a compiler treats a variable as constant within an interface like this:

//public static final constantName = value;
public static final pie= 3.14; 

Interface having a static method

A static method doesn’t depend upon the instance of a class. Therefore, it executes independently.

Program:

interface xyz{
static void print(){
System.out.println("Executing static method");
}
}
class abc implements xyz{

}
public class InterfaceStatic implements xyz{

public static void main(String[] args) {
xyz.print();

}

}

Output:

static method

]]>
https://programmerbay.com/what-is-java-interface-with-examples/feed/ 0