Finding slope, rise and run.

OurNation 0 Tallied Votes 276 Views Share

When this program is run it asks for the coordinate grid points, then it processes that and the result is the run rise and slope.

//SLOPE

import java.io.*;
public class SLOPE  {
  public static void main(String args [ ]) {
     //Where the variables are declared
     String sone;
     String stwo;
     String sthree;
     String sfour;
     float one, two, three, four;
     double rise, run; 
     BufferedReader reader;
     reader  =  new BufferedReader(new InputStreamReader(System.in));

     System.out.print("\nThe first x = ");
   // Where the user input is aquired
   try   {
   sone = reader.readLine( );
   System.out.print("The first y = ");
    stwo = reader.readLine( );
    System.out.print("The second x = ");
    sthree = reader.readLine( );
     System.out.print("The second y = ");
    sfour = reader.readLine( );
     //Converting the user input to floating numbers allowing negitives decimals ect to be used
     one = Float.parseFloat(sone) ;
     two = Float.parseFloat(stwo) ;
     three= Float.parseFloat(sthree) ;
      four = Float.parseFloat(sfour) ;

      rise = four - two;
      run = three - one;
      
    
     
      //The answers
       System.out.println("The rise = " + rise) ;
       System.out.println("The run = " + run );
       System.out.println("The slope is ");
       System.out.println(rise);
       System.out.println("____");
       System.out.println(run);
       
      reader.close ( );	
    //The exceptions if an error accours	
   }
      catch (IOException ioe) {
      System.out.println("Error");
  }
      catch (NumberFormatException nfe) {
      System.out.println("Error");	
  }
      
	
  }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.