...

/

Discrete Mathematics and Computer Science

Discrete Mathematics and Computer Science

Learn how to strengthen the relationship between discrete mathematics and computer science.

Math and computer science

Now we know how discrete mathematics and computer science are related. Moreover, we can reproduce continuous mathematics in any programming language, like Java, through our programming logic and algorithm.

To better understand this, let’s look at another code followed by a discussion on the concept.

//Finding the y-coordinate of a point on a line where x-coordinate is given

import java.util.Scanner;
//FindingYCoordinate
class Main{
    static int lineSlope = 0;
    static int yIntercept = 0;
    static int xCoordinate = 0;
    static int yCoordinate = 0;

    public static void main(String[] args) {
        System.out.println("Enter the value of the line-slope as a positive integer: ");
        Scanner slopeOfLine = new Scanner(System.in);
        lineSlope = slopeOfLine.nextInt();
        System.out.println("Enter the intercept of the y-axis: ");
        Scanner interceptOfY = new Scanner(System.in);
        yIntercept = interceptOfY.nextInt();
        System.out.println("Enter the value of the x-coordinate: ");
        Scanner coordinateOfX = new Scanner(System.in);
        xCoordinate = coordinateOfX.nextInt();
        yCoordinate = lineSlope * xCoordinate + yIntercept;
        
        //line of slope = rise vertically/run horizontally
        //yCoordinate = (lineSlope * xCoordinate) + yIntercept;
        System.out.println("y-coordinate is: " + yCoordinate + " when the slope of the line is: " + lineSlope + "\nIntercept of y-axis is: " + yIntercept + "\nx-coordinate is: "+xCoordinate);
    }
}
Java code for finding the y-coordinate

If we run the program and provide the values, the output comes out as:

Enter the value of the line-slope as a positive integer: 
6
Enter the intercept of the y-axis: 
2
Enter the value of the x-coordinate: 
2
y-coordinate is: 14 when the slope of the line is: 6
Intercept of y-axis is: 2
x-coordinate is: 2

In the output above, we see that every number is discrete, and computing them is easier with the help of a formula. Here, the value of yCoordinate is 14 when xCoordinate is 2. This program in Java is replicable in all programming languages

In the code above: ...