Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么may arrayList只显示一个字符串? java.util.*; 导入java.io.*; 公共类网站 { 字符串country2,city2; int days2,计数=0,时间=10; 双费率2,scost=0; 公共站点(字符串省、字符串市、整数天、双倍费率) { country2=省; 城市2=城市; days2=天; 比率2=比率; } 公共网站() { { 扫描仪扫描=新扫描仪(System.in); 尝试 { 而(计数=0) { BufferedReader file2=新的BufferedReader(新的文件阅读器(“Sites.txt”); while(file2.ready()) { 字符串cityS=file2.readLine(); 字符串site1=file2.readLine(); String cost1=file2.readLine(); double cost1a=double.parseDouble(cost1); 双tcost1=成本1A*费率2; 字符串site2=file2.readLine(); String cost2=file2.readLine(); double cost2a=double.parseDouble(cost2); 双tcost2=成本2A*费率2; 字符串site3=file2.readLine(); String cost3=file2.readLine(); double cost3a=double.parseDouble(cost3); 双tcost3=成本3A*费率2; 字符串wiggle=file2.readLine(); if(城市同等信号案例(城市2)) { System.out.println(“省/地区:+country2+”剩余天数:+days2); System.out.println(“城市:+city2+”时间:“+Time+”:00”); System.out.println(“”); System.out.println(“您想去哪里?”); System.out.println(“1)”+site1); 系统输出打印项次(“成本)”+成本1); System.out.println(“”); System.out.println(“2)”+site2); 系统输出打印项次(“成本)”+成本2); System.out.println(“”); System.out.println(“3)”+site3); 系统输出打印项次(“成本)”+成本3); System.out.println(“”); System.out.println(“4)Eat”); 系统输出打印项次(“成本”)25; System.out.println(“”); 系统输出打印项次(“5)剩余项”); 系统输出打印项次(“成本”)0; System.out.println(“”); int answer=scan.nextInt(); ArrayList数组=新的ArrayList(); 吃东西=新吃东西(答案,城市2,比率2,数组); 描述总和=新描述(站点1、站点2、站点3、答案); 开关(应答) { 案例1:时间=时间+2; scost=scost+tcost1; sum.Description(); array.add(site1); System.out.println(“”); 打破 案例2:时间=时间+2; scost=scost+tcost2; sum.Description(); array.add(site2); System.out.println(“”); 打破 案例3:时间=时间+2; scost=scost+tcost3; sum.Description(); array.add(site3); System.out.println(“”); 打破 案例4:时间=时间+2; scost=scost+(速率2*25); 食物; 打破 案例5:时间=时间+2; System.out.println(“你休息了几个小时。”); 打破 } 如果(时间=22) { days2=days2-1; 时间=10; } 如果(days2==0) { 计数++; 对于(int i=0;i_Java_String_Printing_Arraylist - Fatal编程技术网

为什么may arrayList只显示一个字符串? java.util.*; 导入java.io.*; 公共类网站 { 字符串country2,city2; int days2,计数=0,时间=10; 双费率2,scost=0; 公共站点(字符串省、字符串市、整数天、双倍费率) { country2=省; 城市2=城市; days2=天; 比率2=比率; } 公共网站() { { 扫描仪扫描=新扫描仪(System.in); 尝试 { 而(计数=0) { BufferedReader file2=新的BufferedReader(新的文件阅读器(“Sites.txt”); while(file2.ready()) { 字符串cityS=file2.readLine(); 字符串site1=file2.readLine(); String cost1=file2.readLine(); double cost1a=double.parseDouble(cost1); 双tcost1=成本1A*费率2; 字符串site2=file2.readLine(); String cost2=file2.readLine(); double cost2a=double.parseDouble(cost2); 双tcost2=成本2A*费率2; 字符串site3=file2.readLine(); String cost3=file2.readLine(); double cost3a=double.parseDouble(cost3); 双tcost3=成本3A*费率2; 字符串wiggle=file2.readLine(); if(城市同等信号案例(城市2)) { System.out.println(“省/地区:+country2+”剩余天数:+days2); System.out.println(“城市:+city2+”时间:“+Time+”:00”); System.out.println(“”); System.out.println(“您想去哪里?”); System.out.println(“1)”+site1); 系统输出打印项次(“成本)”+成本1); System.out.println(“”); System.out.println(“2)”+site2); 系统输出打印项次(“成本)”+成本2); System.out.println(“”); System.out.println(“3)”+site3); 系统输出打印项次(“成本)”+成本3); System.out.println(“”); System.out.println(“4)Eat”); 系统输出打印项次(“成本”)25; System.out.println(“”); 系统输出打印项次(“5)剩余项”); 系统输出打印项次(“成本”)0; System.out.println(“”); int answer=scan.nextInt(); ArrayList数组=新的ArrayList(); 吃东西=新吃东西(答案,城市2,比率2,数组); 描述总和=新描述(站点1、站点2、站点3、答案); 开关(应答) { 案例1:时间=时间+2; scost=scost+tcost1; sum.Description(); array.add(site1); System.out.println(“”); 打破 案例2:时间=时间+2; scost=scost+tcost2; sum.Description(); array.add(site2); System.out.println(“”); 打破 案例3:时间=时间+2; scost=scost+tcost3; sum.Description(); array.add(site3); System.out.println(“”); 打破 案例4:时间=时间+2; scost=scost+(速率2*25); 食物; 打破 案例5:时间=时间+2; System.out.println(“你休息了几个小时。”); 打破 } 如果(时间=22) { days2=days2-1; 时间=10; } 如果(days2==0) { 计数++; 对于(int i=0;i

为什么may arrayList只显示一个字符串? java.util.*; 导入java.io.*; 公共类网站 { 字符串country2,city2; int days2,计数=0,时间=10; 双费率2,scost=0; 公共站点(字符串省、字符串市、整数天、双倍费率) { country2=省; 城市2=城市; days2=天; 比率2=比率; } 公共网站() { { 扫描仪扫描=新扫描仪(System.in); 尝试 { 而(计数=0) { BufferedReader file2=新的BufferedReader(新的文件阅读器(“Sites.txt”); while(file2.ready()) { 字符串cityS=file2.readLine(); 字符串site1=file2.readLine(); String cost1=file2.readLine(); double cost1a=double.parseDouble(cost1); 双tcost1=成本1A*费率2; 字符串site2=file2.readLine(); String cost2=file2.readLine(); double cost2a=double.parseDouble(cost2); 双tcost2=成本2A*费率2; 字符串site3=file2.readLine(); String cost3=file2.readLine(); double cost3a=double.parseDouble(cost3); 双tcost3=成本3A*费率2; 字符串wiggle=file2.readLine(); if(城市同等信号案例(城市2)) { System.out.println(“省/地区:+country2+”剩余天数:+days2); System.out.println(“城市:+city2+”时间:“+Time+”:00”); System.out.println(“”); System.out.println(“您想去哪里?”); System.out.println(“1)”+site1); 系统输出打印项次(“成本)”+成本1); System.out.println(“”); System.out.println(“2)”+site2); 系统输出打印项次(“成本)”+成本2); System.out.println(“”); System.out.println(“3)”+site3); 系统输出打印项次(“成本)”+成本3); System.out.println(“”); System.out.println(“4)Eat”); 系统输出打印项次(“成本”)25; System.out.println(“”); 系统输出打印项次(“5)剩余项”); 系统输出打印项次(“成本”)0; System.out.println(“”); int answer=scan.nextInt(); ArrayList数组=新的ArrayList(); 吃东西=新吃东西(答案,城市2,比率2,数组); 描述总和=新描述(站点1、站点2、站点3、答案); 开关(应答) { 案例1:时间=时间+2; scost=scost+tcost1; sum.Description(); array.add(site1); System.out.println(“”); 打破 案例2:时间=时间+2; scost=scost+tcost2; sum.Description(); array.add(site2); System.out.println(“”); 打破 案例3:时间=时间+2; scost=scost+tcost3; sum.Description(); array.add(site3); System.out.println(“”); 打破 案例4:时间=时间+2; scost=scost+(速率2*25); 食物; 打破 案例5:时间=时间+2; System.out.println(“你休息了几个小时。”); 打破 } 如果(时间=22) { days2=days2-1; 时间=10; } 如果(days2==0) { 计数++; 对于(int i=0;i,java,string,printing,arraylist,Java,String,Printing,Arraylist,在循环的每次迭代中都要声明ArrayList 尝试在扫描仪声明上方声明ArrayList 例如 移动 java.util.*; import java.io.*; public class Sites { String country2, city2; int days2, count = 0, time = 10; double rate2, scost = 0; public Sites(String province, String city, int

在循环的每次迭代中都要声明ArrayList

尝试在扫描仪声明上方声明ArrayList

例如

移动

java.util.*;
import java.io.*;

public class Sites 
{
    String country2, city2;
    int days2, count = 0, time = 10;
    double rate2, scost = 0;

    public Sites(String province, String city, int days, double rate)
    {
        country2 = province;
        city2 = city;
        days2 = days;
        rate2 = rate;
    }

    public void Sites() 
    {
        {
            Scanner scan = new Scanner(System.in);
            try
            {
                while(count == 0)
                {
                    BufferedReader file2 = new BufferedReader(new FileReader ("Sites.txt"));
                    while(file2.ready())
                    {
                        String cityS = file2.readLine();

                        String site1 = file2.readLine();
                        String cost1 = file2.readLine();
                        double cost1a = Double.parseDouble(cost1);
                        double tcost1 = cost1a * rate2;

                        String site2 = file2.readLine();
                        String cost2 = file2.readLine();
                        double cost2a = Double.parseDouble(cost2);
                        double tcost2 = cost2a * rate2;

                        String site3 = file2.readLine();
                        String cost3 = file2.readLine();
                        double cost3a = Double.parseDouble(cost3);
                        double tcost3 = cost3a * rate2;

                        String wiggle = file2.readLine();

                        if (cityS.equalsIgnoreCase(city2))
                        {
                            System.out.println("Province/Territory: " + country2 + "Number of Days Left: " + days2);
                            System.out.println("City: " + city2 + "Time: " + time + ":00");

                            System.out.println("");

                            System.out.println("Where would you like to go?");
                            System.out.println("1)" + site1);
                            System.out.println("Cost) " +cost1 );
                            System.out.println("");

                            System.out.println("2)" + site2);
                            System.out.println("Cost) " +cost2 );
                            System.out.println("");

                            System.out.println("3)" + site3);
                            System.out.println("Cost) " +cost3 );
                            System.out.println("");

                            System.out.println("4)Eat");
                            System.out.println("Cost) 25 ");
                            System.out.println("");

                            System.out.println("5)Rest");
                            System.out.println("Cost) 0 ");
                            System.out.println("");

                            int answer = scan.nextInt();

                            ArrayList<String> array = new ArrayList<String>();

                            Eat food = new Eat(answer,city2,rate2,array);
                            Descriptions sum = new Descriptions(site1,site2,site3,answer);

                            switch(answer)
                            {
                            case 1: time = time + 2;
                                    scost = scost + tcost1;
                                    sum.Description();
                                    array.add(site1);
                                    System.out.println("");
                            break;
                            case 2: time = time + 2;
                                    scost = scost + tcost2;
                                    sum.Description();
                                    array.add(site2);
                                    System.out.println("");
                            break;
                            case 3: time = time + 2;
                                    scost = scost + tcost3;
                                    sum.Description();
                                    array.add(site3);
                                    System.out.println("");
                            break;
                            case 4: time = time + 2;
                                    scost = scost + (rate2*25);
                                    food.Eat();
                            break;
                            case 5: time = time + 2;
                                    System.out.println("You rested for a couple of hours.");
                            break;
                            }

                            if(time == 22)
                            {
                                days2 = days2 - 1;
                                time = 10;
                            }

                            if(days2 == 0)
                            {
                                count++;

                                for (int i = 0; i < array.size(); i++)
                                {
                                System.out.println("Thank you for using the tourist simulator. You spent " + scost + " and visited " +array.get(i));
                                }
                            }

                        }
                    }

                }

            }
            catch (IOException e)
            {
                System.out.println(e);
            }

        }
    }
}
ArrayList<String> array = new ArrayList<String>();
Scanner scan = new Scanner(System.in);