English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

import java.io.*;

public class slope extends Object
{
public static void main(String[] args)
{

try
{
BufferedReader myReader =
new BufferedReader(new InputStreamReader(System.in));

// Prompt the user for x and y coordinates for the
// first point and read them in.
System.out.println( "Enter x coordinate of the first point : ");
string input = myReader.readLine();
double x1 = Double.parseDouble( input );
System.out.println( "Enter y coordinate of the first point : ");
string input = myReader.readLine();
double y1 = Double.parseDouble( input );
// Prompt the user for x and y coordinate for the
// second point and read them in.
System.out.println( "Enter x coordinate of the second point : ");
string input = myReader.readLine();
double x2 = Double.parseDouble( input );
System.out.println( "Enter y coordinate of the second point : ");
string input = myReader.readLine();
double y2 = Double.parseDouble( input );
double lineSlope = (x2 - x1) / (y2 - y1);
System.out.println( "The slope of the line is " + lineSlope);
}
catch(Exception e)
{
System.out.println("bad input");
System.exit(1);
}




// End main
}
}

2006-09-05 15:43:57 · 3 answers · asked by mark79_24 1 in Computers & Internet Programming & Design

3 answers

you've declared a string input 4 times, you can't do that!!

just remove the word string from the last three inputs.

this is the correct code:



import java.io.*;

public class slope extends Object
{
public static void main(String[] args)
{

try
{
BufferedReader myReader =
new BufferedReader(new InputStreamReader(System.in));

// Prompt the user for x and y coordinates for the
// first point and read them in.
System.out.println( "Enter x coordinate of the first point : ");
string input = myReader.readLine();
double x1 = Double.parseDouble( input );
System.out.println( "Enter y coordinate of the first point : ");
input = myReader.readLine();
double y1 = Double.parseDouble( input );
// Prompt the user for x and y coordinate for the
// second point and read them in.
System.out.println( "Enter x coordinate of the second point : ");
input = myReader.readLine();
double x2 = Double.parseDouble( input );
System.out.println( "Enter y coordinate of the second point : ");
input = myReader.readLine();
double y2 = Double.parseDouble( input );
double lineSlope = (x2 - x1) / (y2 - y1);
System.out.println( "The slope of the line is " + lineSlope);
}
catch(Exception e)
{
System.out.println("bad input");
System.exit(1);
}




// End main
}
}

2006-09-05 15:59:57 · answer #1 · answered by GNR Sam 3 · 0 0

Andy T and GNR Sam are both right but you can try first to use String on the declaration not string
JP

2006-09-06 06:49:31 · answer #2 · answered by JP 3 · 0 0

In addition, shouldn't it be String? Not string

2006-09-05 23:06:40 · answer #3 · answered by Andy T 7 · 0 0

fedest.com, questions and answers