methods

How can I access this m1() method in the following program?

让人想犯罪 __ 提交于 2020-01-06 06:24:21
问题 How can i access the x = 15 value from m2() ? I am accessing following values as given in comment of the program. class A { int x = 10; void m1(){ int x = 15; //How can we access x =15 ? class B{ int x =20; void m2(){ int x = 25; System.out.println(x); //for x = 25 System.out.println(this.x); //for x = 20 System.out.println(A.this.x); //for x = 10 System.out.println(); } } } } 回答1: Actually, you can't get access to x defined in m1() . To fix it, you could change the variable name: void m1() {

How to run method with JProgressBar

可紊 提交于 2020-01-06 04:45:30
问题 I have a function called CreateAccount . I need it to run and also need to show a progress bar. When I click the button, the method will start. And I need to start showing loading progress bar. Once method is done progress bar also should stop at 100. If the method gets more time to do the job, progress bar also needs to load slowly. I tried using following code but it is not synchronizing progress bar with the method. So how can I do that? Here is my code: private static int t = 0; private

What is the difference between command and bind in tkinter?

醉酒当歌 提交于 2020-01-06 03:07:06
问题 I'm trying to make a button print a string when it's pressed and print another when it's released. I know about the command atribute and the bind method, but I would like to know if it's possible to accomplish it only using atributes or if I have to use methods. With this piece of code: class motor: def __init__(eleMesmo, eixo , valorZero): eleMesmo.eixo = eixo eleMesmo.zero = valorZero def aumenta(self): print(self.eixo + str(self.zero+5)) def diminui(self): print(self.eixo + str(self.zero-5

I am trying to reverse a two dimensional array and keep getting a null exception

拈花ヽ惹草 提交于 2020-01-06 02:16:28
问题 Here is my method that is suppose to reverse the array. (Also, keep in mind that this method can receive a jagged array) public static int[][] reverse(int[][]a){ int[][] rev = new int[a.length][]; int row = a.length; for(int x=0;x<a.length;x++){ int col = a[x].length-1; for(int y=0; y< a[x].length;y++){ rev[row-1][col-1]= a[x][y]; col--; } row--; } return rev; }// reverse method I keep getting Exception in thread "main" java.lang.NullPointerException at Home.reverse(Home.java:259) at Home

How to find the first value in a linked list?

こ雲淡風輕ζ 提交于 2020-01-05 17:38:28
问题 I have a linked list I'm given and I need to find the first value in the list via a getFirst method.I need to display an error message and quit the program if the value is null. The linked list is already given to me link so: class MyLinkedList { private class Node // inner class { private Node link; private int x; } //---------------------------------- private Node first = null; // initial value is null //---------------------------------- public void addFirst(int d) { Node newNode = new

What is the difference between object.method(a,b) and method(a,b) in Ruby

人走茶凉 提交于 2020-01-05 12:23:25
问题 I am very new to programming and am trying to learn Ruby. I can't quite get my head around methods at the moment. I uderstand that: Methods allow me to execute a chunk of code without having to rewrite it, such a method looks like: example_method Arguments allow me to pass values into the code within the method that go in the place of the placeholders defined in the method. This way I can execute a set of code with different inputs. Methods with arguments look like: example_method( x , y )

What is the difference between object.method(a,b) and method(a,b) in Ruby

。_饼干妹妹 提交于 2020-01-05 12:23:11
问题 I am very new to programming and am trying to learn Ruby. I can't quite get my head around methods at the moment. I uderstand that: Methods allow me to execute a chunk of code without having to rewrite it, such a method looks like: example_method Arguments allow me to pass values into the code within the method that go in the place of the placeholders defined in the method. This way I can execute a set of code with different inputs. Methods with arguments look like: example_method( x , y )

communication between run() method and other class method (java threads)

旧时模样 提交于 2020-01-05 11:56:29
问题 i have task to do and i'm little stuck. I have to make 4 services (A,B,C,D). Every service should have his own thread. They should start in sequence and run. If service A starts then can start service B, if service B starts if service C starts then can start service D. I manage to create service and their threads but i dont know how should i create communication between start() and priority() method in PriorityService class. I wan to check if service(thread) A is alive and if it is I want to

How to invoke a non-public method through Reflection without worrying about the method visibility?

坚强是说给别人听的谎言 提交于 2020-01-05 08:56:28
问题 I'm just testing reflection things for curiosity and I'm trying to invoke a private method but I can't find it because is Private . But what I really would like to know is if the visibility of the method could be automatically retrieved in the reflection search to don't worry about if the method to invoke is private, shared, friend, public etc... so there is a BindingFlags flags combination to be able to invoke a method indifferently of which is the method visibility?, I mean without worrying

Java Stack method (multipop) Beginner java

瘦欲@ 提交于 2020-01-05 08:42:29
问题 I'm trying to write a Java method to preform a "multi-pop" off a stack. It should perform a "pop" operation on a stack object k number of times. This is what I'm thinking, but it's not quite right. Any help out there? public void multipop(int k) { while (top != null) { for (int i = 0; i <= k; i++) { this.pop(); } } } 回答1: Looks like an off-by-one error. If k=1 , you will go through the loop with i=0 and i=1 . You can fix this by changing i<=k to i<k 回答2: You execute the while loop until the