0
import java.util.Scanner;文字列をIntに変更してそれを掛ける方法
次に、ユーザは、開口部からそれを差し引くと番号を購入し、現在の価格で購入または売却を希望する金額を乗算しようとしているパブリッククラスpredictStockMarket {
public static void main(String args[]){
int openingPrice;
int currentPrice;
int numberOfStocks;
String buyOrSell;
int buyNumber;
int sellNumber;
Scanner number=new Scanner(System.in);
Scanner text=new Scanner(System.in);
System.out.println("What is the Opening Price? ");//Asking for the opening price
openingPrice=number.nextInt(); //storing into current price variable
System.out.println("What is the Current Price? ");//Asking for the Current Price
currentPrice=number.nextInt(); //storing into current price variable
System.out.println("Do you want to buy or sell? ");//Asking if they want to buy or sell
buyOrSell=text.nextLine();
if (buyOrSell.equalsIgnoreCase("buy")){
System.out.println("How many stock do you want to buy ");//Asking the user for hours per week
int x = Integer.parseInt(buyOrSell);
buyNumber=number.nextLine();
int i;
i = (buyNumber*currentPrice)-(openingPrice*buyNumber);
System.out.println(i);
}
else {
System.out.println("How many stock do you want to sell");
sellNumber=number.nextLine();
int i;
i = (sellNumber*currentPrice)-(openingPrice*sellNumber);
System.out.println(i);
}
イム。
私はそれがユーザーの入力を読んでいないという問題点を有し、かつ、文字列を与えていますが
'' x = Integer.parseInt(buyOrSell); '' 'buyOrSell'が見た目で何らかの並べ替えになるときです。 – user123
'nextInt'と' nextLine'に呼び出しを混ぜるのは賢明ではありません。 –