methods

When given a pair of ints, I need my code to be able to return the int that is closest to 21 without going over [closed]

随声附和 提交于 2019-12-13 09:33:50
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . // blackjack(7,17) -> 17 // blackjack(21, 16) -> 21 // blackjack(19,23) -> 19 public int blackjack(int a, int b) { } After this I am really unsure of how to go about writing this code. 回答1: Hi use this code. if(a<=21 && b<=21){ return Math.max(a, b); } This is a easy problem, try

Java- Accesing instances of a class in a method

点点圈 提交于 2019-12-13 09:25:39
问题 I have to write a code for class that takes in a temperature value, converts it to kelvin, and then determines if this is greater than, equal to, less than, or whatever to another entered temp. It has to say true or false for each of the boolean possibilities. I can't get it to compare the temperature that is set as t1, with the temperature t that the boolean methods take as a parameter? Any suggestions? Also, quit downvoting me, I know I don't know what I'm doing thats why I asked the

Find the smallest element in an array. [closed]

怎甘沉沦 提交于 2019-12-13 09:23:29
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I think the problem lies with the invoking of the method or the braces, not 100% sure. When I call the method does it matter if it before or after the main method? public class varb { public static void main (String[] args) { double[] array = new double [10]; java.util.Scanner input = new java.util

Problems adding objects from a different class into an Arraylist - java

穿精又带淫゛_ 提交于 2019-12-13 09:18:32
问题 I'm working on a project where i have 3 different classes creating objects CommissionEmployee, SalariedEmployee and HourlyEmployee. I need to add these to an arraylist in the main class, but not sure where i'm going wrong. public class Company { public String companyName; public SalariedEmployee owner; public ArrayList<SalariedEmployee> salariedEmployee; public ArrayList<HourlyEmployee> hourlyEmployee; public ArrayList<CommissionEmployee> commissionEmployee; public Company (String companyName

How can I create an Array method in Swift similar to sort, filter, reduce, and map?

泄露秘密 提交于 2019-12-13 08:44:53
问题 I have a question, during study of closure. I want make datatypes closure method like in array types .sort(), .filter(), .reduce(), .map() But how can I make this things. Its datatype not a class. I want make array.somemethod({closure}) not a Somefunc(input: array, closure : { .... }) - Can I make datatype method in swift? otherwise, I can use func only? 回答1: You just need extend Array and pass a closure as your method argument. Lets say you would like to create a mutating method to work as

Indentation Error [closed]

梦想与她 提交于 2019-12-13 08:36:31
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . I'm trying to define a method similar to the method max but I get an error for an expected indentation. I'm not exactly sure what is wrong with the code.

Trying to write my own all? method in Ruby

喜欢而已 提交于 2019-12-13 08:30:18
问题 There is a method called all? in Enumerable. I'm trying to learn all the methods of Enumberable's library by writing them myself. This is what I've come up so far for the all? method. I sorta understand it but I got stumped when trying to pass initialized values to my method. EDIT for the record, I'm aware that enum method that I have is not the right way ie, it's hard-coded array. This is for self-learning purposes. I'm just trying to figure out how to pass the initialized values to my all?

Creating a method from calling two classes in java [closed]

若如初见. 提交于 2019-12-13 08:26:23
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm not sure which one of my methods that's not working. When i create accounts from addSavingsAccount everything is working fine, but when I want to print out the info from two classes it prints name and pNr but shows the first accountnumber to all clients. What's wrong with this? //this works fine public int

AsyncTask, multiple different operations

给你一囗甜甜゛ 提交于 2019-12-13 08:24:11
问题 I currently have one class with 4 methods. I need to change that to AsyncTask. Every method receives different parameters (File, int, String ...) to work with and connects to different URL with post or get. My question is can I still somehow have all those operations in one AsyncTask class or I will need to create new AsyncTask class for every method? private class Task extends AsyncTask<URL, Integer, Long> { protected Long doInBackground(URL... urls) { int count = urls.length; long totalSize

Calling a Method Once [closed]

折月煮酒 提交于 2019-12-13 08:22:31
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I am having a problem of how to call a method once when the condition achieves many times! for example: public void onLocaitonChanged(Location location){ // this if statement may achieve the condition many times if(somethingHappened){ callAMethodOnce();// this method is called once even if the