从txt文件中读取每个其他行并保存到数组中(Reading every other line from a txt file and saving into an array)
作业:你的小表弟所在的学校正在卖饼干。 如果你堂兄的班级销售的饼干数量超过其他任何课程,那么老师就答应让全班学生去野餐。 当然,你的堂兄自告奋勇跟踪所有销售情况并确定获胜者。
每个班级都由老师的名字识别。 每个销售单都有教师姓名和售出的盒子数量。 您决定创建两个并行阵列:一个用于保存教师的名称,另一个用于记录销售的盒子数量。 以下是数据示例:
第一个数字给出了课程的数量,然后一个教师的名字后跟出售的盒子数量15史密斯3考特尼......等等等等
我的主要问题(因为我可以将其复制为“将来的”并行数组)是将所有其他行保存到已售出的盒子的数组中,因此数组“boxSold”看起来像
[1] 15
[2] 3package assignment5Package; import java.util.Scanner; import java.io.*; public class assignment5Demo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub //create arrays, variables Scanner keyboard = new Scanner(System.in); BufferedReader input = new BufferedReader (new FileReader ("/Users/lee/Desktop/class/cs 113/Assignment5/cookies.txt")); System.out.println("How many sale slips are there"); int numSaleSlips = keyboard.nextInt(); int[] soldBox = new int[numSaleSlips]; //______String[] teacherName = new String[numSaleSlips]; int soldBoxIndex; int teacherNameIndex; //String soldBoxString; (line 50) //initializing both strings to 0 and "_" for (soldBoxIndex = 0; soldBoxIndex < numSaleSlips; soldBoxIndex++) { soldBox[soldBoxIndex] = 0; } //**for (teacherNameIndex = 0; teacherNameIndex < numSaleSlips; teacherNameIndex++) //**{ //** teacherName[teacherNameIndex] = "_"; //**} //reading from the cookies.txt file for (soldBoxIndex = 0; soldBoxIndex < numSaleSlips; soldBoxIndex++) { if (soldBoxIndex % 2 != 0 { String soldBoxString; soldBoxString = input.readLine(); //reads in value and assigns/re-assigns soldBox[numSaleSlips] = (int) Double.parseDouble(soldBoxString); //type-casted to fit variable type, converts to double, stores in array System.out.println(soldBox[soldBoxIndex]); } else { System.out.println("Error at " + soldBoxIndex +"."); } } }
assignment: A school that your little cousin attends is selling cookies. If your cousin's class sells more cookies than any other class, the teacher has promised to take the whole class on a picnic. Of course, your cousin volunteered you to keep track of all the sales and determine the winner.
Each class is identified by the teacher's name. Each sales slip has the teacher's name and the number of boxes sold. You decide to create two parallel arrays: one to hold the teacher's names and one to record the number of boxes sold. Here is a sample of the data:
The first number gives the number of classes, and then a teacher's Name is followed by the number of boxes sold 15 Smith 3 Courtney ... so on so forth
My main issue (because i can just duplicate it for the "to-be" parrallel array) is getting every other line to save into an array for the boxes sold so array "boxSold" would look like
[1] 15
[2] 3package assignment5Package; import java.util.Scanner; import java.io.*; public class assignment5Demo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub //create arrays, variables Scanner keyboard = new Scanner(System.in); BufferedReader input = new BufferedReader (new FileReader ("/Users/lee/Desktop/class/cs 113/Assignment5/cookies.txt")); System.out.println("How many sale slips are there"); int numSaleSlips = keyboard.nextInt(); int[] soldBox = new int[numSaleSlips]; //______String[] teacherName = new String[numSaleSlips]; int soldBoxIndex; int teacherNameIndex; //String soldBoxString; (line 50) //initializing both strings to 0 and "_" for (soldBoxIndex = 0; soldBoxIndex < numSaleSlips; soldBoxIndex++) { soldBox[soldBoxIndex] = 0; } //**for (teacherNameIndex = 0; teacherNameIndex < numSaleSlips; teacherNameIndex++) //**{ //** teacherName[teacherNameIndex] = "_"; //**} //reading from the cookies.txt file for (soldBoxIndex = 0; soldBoxIndex < numSaleSlips; soldBoxIndex++) { if (soldBoxIndex % 2 != 0 { String soldBoxString; soldBoxString = input.readLine(); //reads in value and assigns/re-assigns soldBox[numSaleSlips] = (int) Double.parseDouble(soldBoxString); //type-casted to fit variable type, converts to double, stores in array System.out.println(soldBox[soldBoxIndex]); } else { System.out.println("Error at " + soldBoxIndex +"."); } } }
原文:https://stackoverflow.com/questions/13600772
最满意答案
在您的PDA可以使用的服务器上构建RESTful API。
至于服务器到客户端的通信,Android可以使用C2DM框架 。 这会向您的Android设备发送通知,然后您的Android设备可能会与服务器联系。 我相信iOS有一个相似的概念。 对于Windows Mobile,您可以使用自己的通知协议(或基于HTTP的通信协议)使用原始套接字(客户端发起的与服务器的连接),也可以使用特制消息开发SMS intereceptor ,以便客户端知道要与服务器。
使用Web服务器可能是件好事。 你会得到一些相当便宜的功能,比如SSL / TLS和认证支持。 将此与原始套接字方法进行比较,数据得到任何人的明确传输。 您将最终构建自己的协议,解决HTTP已经解决的一系列问题。
Build RESTful APIs on the Server that your PDAs can consume.
As for server to client communication, for Android you could use the C2DM framework. This sends a notification to your Android device, and then your Android device could contact the Server. I believe iOS has a similar concept. For Windows Mobile, you could use a raw socket (client initiated connection to the server) with your own notification protocol (or build an HTTP-based one) or perhaps develop an SMS intereceptor with specially crafted messages so that the client knows to contact the server.
Using a Web Server could be a good thing. You get a few features fairly cheap, such as SSL/TLS and authentication support. Compare this to a raw sockets approach, where data gets transmitted in the clear by anybody. You'll end up building your own protocol that solves a bunch of problems HTTP already addresses.
相关问答
更多-
需要POS的架构理念(Need architecture idea for POS)[2024-02-19]
你有多少愿意为我付钱给你建筑? 开玩笑。 想想零售商: 只有10种物品 每天仅售出5件数量的物品 那只有1名员工,这是他/她的家人 那只卖现金而不是电子支付 您是否认为这种零售商需要能够通过云计算支持实现POS的移动应用程序? 当然不是。 他/她可能只需要一本用简单的会计借记信用手工书写的书来跟踪他/她的收入/支出。 但像W * lmart这样的大公司会做。 如果要创建应用程序,请确保您具有该要求。 为什么要创造一些不需要的东西呢? 如果您想制作一般的POS应用程序,请先收集基本要求。 他们需要什么。 他们 ... -
如果pos大于0,则返回pos,否则返回0 它被称为三元操作: http : //en.wikipedia.org/wiki/Ternary_operation if pos is greater than 0, return pos, otherwise return 0 Its called a Ternary Operation: http://en.wikipedia.org/wiki/Ternary_operation
-
与POS系统沟通(Communication with POS system)[2023-12-21]
在您的PDA可以使用的服务器上构建RESTful API。 至于服务器到客户端的通信,Android可以使用C2DM框架 。 这会向您的Android设备发送通知,然后您的Android设备可能会与服务器联系。 我相信iOS有一个相似的概念。 对于Windows Mobile,您可以使用自己的通知协议(或基于HTTP的通信协议)使用原始套接字(客户端发起的与服务器的连接),也可以使用特制消息开发SMS intereceptor ,以便客户端知道要与服务器。 使用Web服务器可能是件好事。 你会得到一些相当便 ... -
ThisStr是一个UTF8String ,你的其他System.Pos()输入是无类型文字。 这是一个需要注意的重要事实,因为它会影响编译器如何调用System.Pos() 。 在D2010中, System单元有三个System.Pos()重载: function Pos(const substr, str: UnicodeString): Integer; overload; function Pos(const substr, str: RawByteString): Integer; overlo ...
-
看起来你首先必须实例化一个通过包含文件的标记器: new MaxentTagger("models/left3words-wsj-0-18.tagger"); 这很糟糕,因为稍后使用的标记方法是静态的: MaxentTagger.tagStringTokenized("here is a string to tag"); 我还必须通过-Xmx256m才能使它在该设置下运行。 It seems you first have to instantiate a tagger passing the inclu ...
-
我从我理解的方式看待它的方式是你必须将它分成数据表 根据您的描述,我们可以识别一些实体, 顾客 信用账户 SaleOrder 产品 完成此设置后,您可以创建一个查询来执行您刚才描述的操作,而不是为您执行此操作,这对于合适的解决方案来说是一个良好的开端。 The way I see it from what I understand is you're going to have to separate this out into data tables From your description we ca ...
-
我们在AbleCommerce和MAS系统之间进行了设置。 我们将产品输入AbleCommerce系统,然后创建了一个流程,将MAS系统中的库存,价格和成本信息推送到ProductVariants表中。 我们遇到的一个问题是,在对变体数据进行更改之前,ProductVariants表中不存在任何记录。 因此,我们必须编写一个存储过程来自动填充ProductVariants表,以便我们可以进行同步。 We've set this up between AbleCommerce and an MAS syste ...
-
斯坦福nlp pos标记(stanford nlp pos tagging)[2023-07-12]
斯坦福CoreNLP当然可以直接做标记。 以下代码行标记您的示例,并为您提供所需的输出。 Properties props = new Properties(); props.setProperty("annotators","tokenize, ssplit, pos"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); Annotation annotation = new Annotation("I'm so happy about m ... -
是。 PosEx函数来自FastCode ,与System.Pos相比要快得多。 它位于StrUtils单位。 Yes. PosEx function is from FastCode and is much faster compared to System.Pos. It is located in StrUtils unit.
-
是的,这是可能的 这种类型的系统正是Rails的用途 你最好研究mvc编程模式 (Rails是围绕它构建的)。 虽然还有很多其他框架可以做同样的事情: 这基本上意味着您拥有一个中央数据存储库(可以在线或不在线),并通过一系列views和controllers访问它。 - 访问 您可以使用的技巧是可以在本地访问数据库,并为接口提供本地网络上的地址。 您必须记住, web server只是运行可从Internet(通过公共IP)获得的软件的计算机。 您需要的是创建一个local服务器(只能从local area ...