methods

They are exact same methods but one works and another does not

Deadly 提交于 2019-12-12 03:37:57
问题 public class L20 { public static void main(String[] args) throws IOException{ Scanner input=new Scanner(System.in); System.out.println("Enter file name"); String in=input.nextLine(); try{ textWriter(in); textReader(in); textChanger(in); }catch(Exception e){ } } public static void textWriter(String path) throws IOException{ String[] alphabet= {"a","b","c","d","e","f","g","h","i","j","k","m","l","n","o","p","q","r","s","t","u","v","w","x","y","z"}; File file=new File(path); Writer output=null;

Unity how can AddComponent<T>()?

眉间皱痕 提交于 2019-12-12 03:27:33
问题 I need to attach a specific script to a GameObject. public T ElegirScript<T>() { switch((int)tipoEdificio) // enum { case 0: return Edificios; // a class/script not instance break; case 1: return PlantaEnergia; // a class/script not instance break; default: break; } } gameobject.AddComponent<ElegirScript()>(); How can I make this? I have errors, thanks. I need first a Method that returns a type or a component, the return must be scripts. then I AddComponent and give the type the program

Using grid_propagate(False) in Python Tkinter

拥有回忆 提交于 2019-12-12 03:23:43
问题 I am creating a frame the uses the grid manager. And I have a label widgets in it. I want the label widget to fill to the frame that it is in. But instead the frame re sizes itself to the label widget. I have tried using the method grid_propagate(False). But it does not seem to be working. I don't know if it is just the way that I am using it but can someone help me figure out why it is not working? def fields(self): frame_row = 0 frame_column = 0 row_count = 0 color = "red" for i in range(50

How to access parameters in a method for an array? Java

醉酒当歌 提交于 2019-12-12 03:23:35
问题 Just trying to understand the basics of how this should work. Here is my code.---------------------------> This is my main class. public class Driver { public static void main(String[] args) { //create new instance of the ArrayLab class with parameter of 10 ArrayLab array = new ArrayLab(10); //search for 2 array.search(2); } } The class ArrayLab has a method assigned to it called search with parameter of (2). So far this is what I have. import java.util.Arrays; public class ArrayLab { //array

method chaining with sub-methods

房东的猫 提交于 2019-12-12 03:17:22
问题 I am trying to use method chain with sub-methods. IE: foo("bar").do.stuff() The catch is stuff() needs to have a reference to the value of bar("bar") Is there any this.callee or other such reference to achieve this? 回答1: Is there any this.callee or other such reference to achieve this? No, you'd have to have foo return an object with a do property on it, which either: Make stuff a closure over the call to foo Have information you want from foo("bar") as a property of do , and then reference

Trouble with Java generics in non-generic class

瘦欲@ 提交于 2019-12-12 03:16:09
问题 public class method { private static class Foo { public void hello() { System.out.println("Foo"); } } private static class Bar { public void hello() { System.out.println("Bar"); } } private static <T> void hello(T typ) { typ.hello(); } public static void main(String args[]) { Foo foo = new Foo(); Bar bar = new Bar(); hello(foo); hello(bar); } } I've looked at the other questions here regarding generics, but despite everything I've seen there and applied to the code I've written, I'm still

Why won't my interface typed objects preform methods that are not declared in the interface?

五迷三道 提交于 2019-12-12 03:08:47
问题 Here is the code I'm having problems with: The interface: public interface anInterface { void printSomething(); } Class that implements the interface: public class aClass implements anInterface { public aClass() { } public void printSomethingElse() { System.out.println("Something else"); } @Override public void printSomething() { System.out.println("Something"); } } And the main function: public static void main(String[] args) { anInterface object = new aClass(); object.printSomething(); //

Suggest a good method name for “running year” [closed]

前提是你 提交于 2019-12-12 03:06:15
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . Please help to come with a nice name for a method. Actually it is a scope that defines limit on date. This limit is from today and 365 days to the past, to the same day in past basically. So this is kind of rolling year I would say. This method is currently named #in_last

Method to find string in text file, then add in string to text file if string is not found else reject entry

白昼怎懂夜的黑 提交于 2019-12-12 02:42:41
问题 public static void main(String[] args) throws IOException{ if (args.length == 1) { BufferedReader bf = new BufferedReader (new FileReader("fruit.txt")); int linecount = 0; String line; //run thur the txt file to check if input exist while (( line = bf.readLine()) != null) { linecount++; int indexfound = line.indexOf(args[0]); if (indexfound > -1) { System.out.println("fruit exist on line " + linecount); System.out.println("add another fruit"); System.exit(0); } else { BufferedWriter bw = new

Searching an array for certain number of integers greater than one integer

冷暖自知 提交于 2019-12-12 02:39:47
问题 I have written this method to find the number of values that are greater than a specific value in an array and it works with arrrays that have positive integers but when I tried this test case it failed. public static int numGreater(int[] a, int val) { if (a == null || a.length == 0) { throw new IllegalArgumentException(); } int[] copy = Arrays.copyOf(a, a.length); Arrays.sort(copy); int answer = 0; int nearest = copy[0]; for (int i = 0; i < copy.length; i++) { if (Math.abs(nearest - val) >