Whats wrong with this im just dumb and couldnt figure it out help please

//SLOPE


import java.io.*;
public class SLOPE  {
public static void main(String args [ ]) {
int Y2, Y1, X2, X1;
BufferedReader reader;


reader  =  new BufferedReader(new InputStreamReader(System.in));
try     {
System.out.print("\nY2 =");
Y2 = Integer.parseInt(reader.readLine( ));
System.out.print("Y1 = ");
Y1 = Integer.parseInt(reader.readLine( ));
System.out.print("X2 = ");
X2 = Integer.parseInt(reader.readLine( ));
System.out.print("X1 = ");
X1 = Integer.parseInt(reader.readLine( ));
reader.close ( );
}
catch (IOException ioe) {
System.out.println("An error accoured while calculating this equation try again");
}
catch (NumberFormatException nfe) {
System.out.println("An error accoured while calculating this equation try again");
}


System.out.println( "The slope is" + ( (Y2 - Y1) / (X2 - X1)));
}
}

Edited 3 Years Ago by happygeek: fixed formatting

wrong forum would be the first thing that's wrong with it...

You don't need that reader either.
And then your calculation will of course always yield an integer value as you're working with only integers.

I rewrote it, but you really need to work on your conventions: indenting, and naming.

import java.io.*;

  public class Slope
  {
     public static void main(String args [ ]) {
     
     	double y2, y1, x2, x1;
 	y2 =0;
	y1 =0;
	x2 =0;
	x1 =0;

	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

	try 
	{
		System.out.print("\nY2 =");
		y2 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("Y1 = ");
		y1 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("X2 = ");
		x2 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("X1 = ");
		x1 = Double.parseDouble(reader.readLine( ));
		
		reader.close ( );
	}
	catch (IOException ioe) 
	{
		System.out.println("An error accoured while calculating this equation try again");
	}
	catch (NumberFormatException nfe) 
	{
		System.out.println("An error accoured while calculating this equation try again");
	}
	
	System.out.println( "The slope is " + getSlope(y2,y1,x2,x1));
   }
   
   public static double getSlope(double y1, double y2, double x1, double x2)
	{
		double yValue = y2-y1;
		double xValue = x2-x1;
		double slope = yValue/xValue;
		
		return 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");
                }


        }

}

I reworte it a long time ago its in the code snipets under find slope rise and run but thanks for posting that anyway :lol: my next project is much more complex and ill post it here when im done

EDIT:The indenting thing is from not wraping the code tags around it it removed the idents i guess when i posted it :o

This article has been dead for over six months. Start a new discussion instead.