這是一個簡單的程序。我被分配存儲在一個數組中的對象。但是因爲我是初學者,所以我不知道如何將對象存儲在數組中。有人可以幫我解決這個問題嗎?在Java中存儲對象數組
import java.util.Scanner;
public class MainExample {
public static void main(String[] args) {
double length;
double width;
double price_per_sqyd;
double price_for_padding;
double price_for_installation;
String input;
double final_price;
boolean repeat = true;
Scanner keyboard = new Scanner(System.in);
while (repeat)
{
System.out.println("\n" +"What is the length of the room?: ");
length = keyboard.nextInt();
System.out.println("What is the width of the room?: ");
width = keyboard.nextInt();
System.out.println("What is the price of the carpet per square yard?: ");
price_per_sqyd = keyboard.nextDouble();
System.out.println("What is the price for the padding?: ");
price_for_padding = keyboard.nextDouble();
System.out.println("What is the price of the installation?: ");
price_for_installation = keyboard.nextDouble();
keyboard.nextLine();
System.out.println("\n" + "Type 'yes' or 'no' if this is correct: ");
input = keyboard.nextLine();
if ("yes".equals(input))
repeat = true;
else
repeat = false;
}
}
}
你的問題還不清楚。你想要存儲什麼? – Maroun
使用Object [] objArray = new Object [length]' – Codebender
如果您的代碼沒有,您想要存儲在對象數組中的對象是什麼。 –