I am trying to grab and store (coordinate1,x1,y1) at the same time .
Here is what I am trying to have happen when someone enteres 2,3:
coordinate = (2,3)
x1=2
y1=3
import java.util.Scanner;
public class LinearSlopeFinder {
public static void main(String[]args){
double x1, y1 ;
Scanner myScanner = new Scanner(System.in);
System.out.print(" What is the first set of cordinants? ... ");
String coordinate1 = myScanner.next();//this is the only thing
//it stores
x1= myScanner.nextInt();//need this from myScanner
y1= myScanner.nextInt();//need this from myScanner
System.out.println("your coordinates are " + coordinate1);
System.out.println("x1 is "+ x1 );
}
}
now trying to split but still getting an error
import java.util.Scanner;
public class LinearSlopeFinder {
public static void main(String[]args){
int x1, y1, x2, y2, n1, equation, slope ;
Scanner myScanner = new Scanner(System.in);
System.out.print(" What is the first set of cordinants? ... ");
String coordinate1 = myScanner.nextLine();
String coordinates[] = coordinate1.split(",");
x1 = coordinates[0];
y1 = coordinates[1];
System.out.println("your cordinants are " + cordinant1);
System.out.println("x1 is "+ x1 );
}
}
Get the line
myScanner.nextLine()and save it tocoordiante1.Split the
coordiante1using,as delimiter (String#split). Cast(Integer#parseInt) & Assign 0th index tox1and 1st index toy1.