•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 426,905 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,300 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 5086 | Replies: 4
![]() |
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)));
}
}
//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)));
}
}
PETA People for the Eating of Tasty Animals.
FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation:
Rep Power: 18
Solved Threads: 199
which reader? Im kinda confused and lost
PETA People for the Eating of Tasty Animals.
FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
•
•
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation:
Rep Power: 9
Solved Threads: 18
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
Last edited by OurNation : Feb 17th, 2005 at 8:27 pm. Reason: forgot somethin'
PETA People for the Eating of Tasty Animals.
FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
![]() |
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Java 3D Environment (Java)
- Java 3D (Java)
- Java Expert (Needed) (Java)
- Java Chat Reboots (Java)
Other Threads in the JSP Forum
- Previous Thread: passing mulitple parameters from jsp to a database
- Next Thread: Multithreading in jsp-HELP!!!



Linear Mode