每次在运行时计算时动态重命名数组
Dynamically renaming an array each time counted in for while in runtime
基本上每次for循环运行时,我都想创建一个新名称的数组。
所以在程序结束时,我将能够打印出包含其中所有单个变量的每个数组。到目前为止,这是我的代码,其中创建了一个数组,但是每次循环语句 运行 它都会覆盖数组。
package clark.motors.car.check.program;
import java.util.*;
public class ClarkMotorsCarCheckProgram {
public static void main(String[] args)
{
//System.out.println(test);
Scanner Input = new Scanner(System.in);
int inputcars = 0;
//List<String> reg3 = new ArrayList<>();
boolean newcar=false;
//int inputcars;
System.out.println("Welcome to Clarke's Automobile Car-Check Program");
System.out.println("Please specify 'Yes' or 'no' if you wish to add a new char to the current list");
System.out.println("");
String text = Input.nextLine();
if(text.equals("yes"))
{
System.out.println("Please specify How many you wish to add");
System.out.println("");
inputcars = Input.nextInt();
Input.nextLine();
//int u = inputcars;
//String strI = "" + u;
}
for (int i=0;i<inputcars;i++)
{
String strI = "" + i;
String test = "person" + i;
Scanner Input2 = new Scanner(System.in);
System.out.println("Please specify the Regristration of the next car");
String reg = Input2.nextLine();
System.out.println("Please specify the color of the next car");
String color = Input2.nextLine();
System.out.println("Please specify how many wheel are on the nect car");
int wheels = Input2.nextInt();
System.out.println("Please specify how many doors are on the next car");
int doors = Input2.nextInt();
System.out.println("Please specify the make of the next car");
String make = Input2.nextLine();
String make2 = Input2.nextLine();
System.out.println("Please specify the state of the next car. 'scrap', 'repairs', 'working'");
String state = Input2.nextLine();
// ClarkMotarsCreateCars reg2 = new ClarkMotarsCreateCars(reg,color,wheels,doors,make,state);
//Map<String, String> details = new HashMap<>();
//List<String> details = new ArrayList <> ();
String details [] = {reg, color, make, state};
int car2 [] = {wheels, doors};
System.out.println("The reg of the car is: "+reg);
System.out.println("The colour of the car is: "+color);
System.out.println("The make of the car is: "+make2);
System.out.println("The state of the car is: "+state);
System.out.println("The amount of wheels on the car: "+wheels);
System.out.println("The amount of doors on the car: "+doors);
}
}
public String details [] = {reg, color, make, state};
}
ArrayList<ClarkMotarsCreateCars> cars = new ArrayList<>();
for(..){
cars.add(new ClarkMotarsCreateCars(reg,color,wheels,doors,make,state));
}
这将为您提供一个对象数组,并且不会覆盖第一个条目。
基本上每次for循环运行时,我都想创建一个新名称的数组。 所以在程序结束时,我将能够打印出包含其中所有单个变量的每个数组。到目前为止,这是我的代码,其中创建了一个数组,但是每次循环语句 运行 它都会覆盖数组。
package clark.motors.car.check.program;
import java.util.*;
public class ClarkMotorsCarCheckProgram {
public static void main(String[] args)
{
//System.out.println(test);
Scanner Input = new Scanner(System.in);
int inputcars = 0;
//List<String> reg3 = new ArrayList<>();
boolean newcar=false;
//int inputcars;
System.out.println("Welcome to Clarke's Automobile Car-Check Program");
System.out.println("Please specify 'Yes' or 'no' if you wish to add a new char to the current list");
System.out.println("");
String text = Input.nextLine();
if(text.equals("yes"))
{
System.out.println("Please specify How many you wish to add");
System.out.println("");
inputcars = Input.nextInt();
Input.nextLine();
//int u = inputcars;
//String strI = "" + u;
}
for (int i=0;i<inputcars;i++)
{
String strI = "" + i;
String test = "person" + i;
Scanner Input2 = new Scanner(System.in);
System.out.println("Please specify the Regristration of the next car");
String reg = Input2.nextLine();
System.out.println("Please specify the color of the next car");
String color = Input2.nextLine();
System.out.println("Please specify how many wheel are on the nect car");
int wheels = Input2.nextInt();
System.out.println("Please specify how many doors are on the next car");
int doors = Input2.nextInt();
System.out.println("Please specify the make of the next car");
String make = Input2.nextLine();
String make2 = Input2.nextLine();
System.out.println("Please specify the state of the next car. 'scrap', 'repairs', 'working'");
String state = Input2.nextLine();
// ClarkMotarsCreateCars reg2 = new ClarkMotarsCreateCars(reg,color,wheels,doors,make,state);
//Map<String, String> details = new HashMap<>();
//List<String> details = new ArrayList <> ();
String details [] = {reg, color, make, state};
int car2 [] = {wheels, doors};
System.out.println("The reg of the car is: "+reg);
System.out.println("The colour of the car is: "+color);
System.out.println("The make of the car is: "+make2);
System.out.println("The state of the car is: "+state);
System.out.println("The amount of wheels on the car: "+wheels);
System.out.println("The amount of doors on the car: "+doors);
}
}
public String details [] = {reg, color, make, state};
}
ArrayList<ClarkMotarsCreateCars> cars = new ArrayList<>();
for(..){
cars.add(new ClarkMotarsCreateCars(reg,color,wheels,doors,make,state));
}
这将为您提供一个对象数组,并且不会覆盖第一个条目。