【发布时间】:2016-12-09 05:26:19
【问题描述】:
所以这可能以前被问过,但我无法真正理解我在网上阅读的所有信息。
public static void balanceSheet(){
//Put in the Company u want to get the data from
Scanner scan= new Scanner(System.in);
System.out.println("Enter your Symbol: ");
String symbol= scan.nextLine();
//Diffrent Websites to visit and get the Data
String url = ("http://www.morningstar.com/stocks/XNAS/"+symbol+"/quote.html");
driver.switchTo().frame(driver.findElement(By.xpath("//*[(@id = 'quote_quicktake')]//iframe")));
String currPrice = driver.findElement(By.id("last-price-value")).getText();
driver.switchTo().defaultContent();
System.out.println("Current Share Pirce: "+currPrice+"$");
}
如何在 calCulator 方法中获取 String currPrice 的值,以便我可以用其他数字计算它?
public void calCulator() {
Scanner calCu = new Scanner(System.in);
System.out.println("Do you want to Calculate the Value?: ");
String calculator = calCu.next();
if(calculator.equals("Yes")) {
System.out.println("the Calculation is: ");
}
else {
System.out.println("ok");
}
}
【问题讨论】:
-
将该值作为参数传递给
calCulator()方法?? -
或将
currPrice存储为字段 -
我可以举个例子吗?这是我的第一个程序,所以我对 java 很陌生
-
"所以这可能以前被问过" -- 是的,在过去的两周里大约有十几次...... StackOverflow 不是一个教程网站,请访问help center 并阅读 How to Ask
-
@BrudgeKisekka - 添加调用
balanceSheet和calCulator的完整代码。通过currPrice无法真正理解您在这里要做什么
标签: java variables methods calculator