檢查數組的總和小於最大時間,如果是,則隨機數生成器將停止,輸出會是這樣:檢查數組的總和必須小於最大時間
No of customer = 3
max time = 4;
customer 1 = 3
customer 2 = 1
total time = 4
//so the customer 3 a
類CstplangsBadango
package cstplangsbadango;
import java.io.*;
import java.util.Random;
import java.util.Scanner;
public class CstplangsBadango {
static int customer = 0;
static int maxTime = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random rand = new Random();
System.out.print("Enter number of customer: ");
customer = sc.nextInt();
System.out.print("Enter number of Maximum time: ");
maxTime = sc.nextInt();
System.out.println(" ");
int[] cust = new int[customer];
int j = 0;
int sum = 0;
int sum1 = 0;
int chu = 0;
for (int i = 0; i < cust.length; i++) {
cust[i] = (int) randomFill();
j += 1;
sum += cust[i];
System.out.println("Customer #" + j + " = " + cust[i]);
}
System.out.println(" ");
System.out.println("Maximum time: " + sum);
}
public static double randomFill() {
Random rand = new Random();
int randomNum = rand.nextInt(3) + 1;
return randomNum;
}
}
客戶3那麼到時候顧客2達到它消耗已經4的計數器,它的最大時間 –
你有一個問題,刪除,因爲?你剛剛說出了你的家庭作業問題併發布了一些代碼,但看起來你忘了提問。 – Jesper
wheres問題?請說明您目前有什麼問題。 – abcOfJavaAndCPP