methods

how to find common suffix in java by using method

拥有回忆 提交于 2020-01-15 08:24:31
问题 How to find common suffix in java by using method public static String commonSuffix (String s1, String s2) I can't return the result in method. Please help me import java.util.Scanner; public class ders1 { public static void main(String[] args) { //HW3 Topic 3 Scanner input = new Scanner(System.in); String reverse1=""; String reverse2=""; System.out.println("Please enter the first string: "); String s1=input.nextLine(); System.out.println("Please enter the second string: "); String s2=input

Python - Add days to an existing date

前提是你 提交于 2020-01-15 06:35:06
问题 Obviously this is homework so I can't import but I also don't expect to be spoon fed the answer. Just need some help on something that's probably pretty simple, but has had me stumped for too many hours now. I have to add days to an existing date in python. Here is my code: class Date: """ A class for establishing a date. """ min_year = 1800 def __init__(self, month = 1, day = 1, year = min_year): """ Checks to see if the date is real. """ self.themonth = month self.theday = day self.theyear

.each() method only applies to first element in IE

血红的双手。 提交于 2020-01-15 05:48:09
问题 I have a jQuery like so: $('#corner .photo img').each(function() { var $img = $(this); var h = $img.height(); var w = $img.width(); $img.css('margin-top', +h / -2 + "px").css('margin-left',+ w/ -2 + "px"); }); It works in all browsers except in IE 7 and 8. In those browsers, it only applies the new property to the first element of #corner (which is the first .photo img). If I remove #corner, it applies to all instances of ".photo img" inside it. However, I cannot remove the id #corner because

Is there any research on ideal METHOD LENGTH?

爷,独闯天下 提交于 2020-01-15 05:15:35
问题 I have read in books and heard at university that methods should not exceed one screen in length. Is there enough empirical evidence to support this hypothesis? Does it really make it easier to spot errors and fix them? 回答1: A summary of research on the subject can be found at: http://dubroy.com/blog/method-length-are-short-methods-actually-worse/ 回答2: A method should be as long as required to perform the task for which it is designed. No shorter and no longer. 回答3: The reason that I have

method overriding Vs class variable overriding in java

℡╲_俬逩灬. 提交于 2020-01-14 19:53:27
问题 I was just trying some sample code for checking class variable overriding behavior in Java. Below is the code: class A{ int i=0; void sayHi(){ System.out.println("Hi From A"); } } class B extends A{ int i=2; void sayHi(){ System.out.println("Hi From B"); } } public class HelloWorld { public static void main(String[] args) { A a= new B(); System.out.println("i->"+a.i); // this prints 0, which is from A System.out.println("i->"+((B)a).i); // this prints 2, which is from B a.sayHi(); // method

Excel 2013 VBA Range.RemoveDuplicates issue specifying array

拟墨画扇 提交于 2020-01-14 14:13:18
问题 The sheets that I am scanning for duplicates have different numbers of columns I'm trying to specify the array of columns for Range.RemoveDuplicates by using a string like this: Let's say there are 5 columns in this sheet Dim Rng As Range Dim i As Integer Dim lColumn As Integer Dim strColumnArray As String With ActiveSheet lColumn = Cells(1, Columns.Count).End(xlToLeft).Column strColumnArray = "1" For i = 2 To lColumn strColumnArray = strColumnArray & ", " & i Next i 'String ends up as "1, 2,

Javascript setInterval runs only one time

徘徊边缘 提交于 2020-01-14 03:48:05
问题 setInterval(this.Animate(), this.speed); This is expected to be run every this.speed times. Yes, but the browsers run it only one time. What are the possible reasons for that? 回答1: If Animate is a derived function from the prototype, you'll have to use: setInterval(this.Animate.bind(this), this.speed); 回答2: Try to run your function without the parentheses, when you put parentheses it always calls the function instead of passing it, which is what you want here: setInterval(this.Animate, this

How can i make a “dice” that randomly generates a number 1-6 EACH time it is used?

☆樱花仙子☆ 提交于 2020-01-13 20:22:29
问题 Right now i am using int die = (int)(6.0 * Math.random()) + 1; This does not work for the loop i am trying to create. This is the method i am using. public void computerRoll() { do { roll(); System.out.println("Roll:"+ die); computerScore += die; } while (computerScore <= 20 && die >=2 && die <=6 ); if (computerScore >=20) computerHold(); if (die == 1) switchTurn(); } The roll() method just simply has the previous line of code in it, "int die = (int)(6.0 * Math.random()) + 1;" i have tried

How can i make a “dice” that randomly generates a number 1-6 EACH time it is used?

不问归期 提交于 2020-01-13 20:20:38
问题 Right now i am using int die = (int)(6.0 * Math.random()) + 1; This does not work for the loop i am trying to create. This is the method i am using. public void computerRoll() { do { roll(); System.out.println("Roll:"+ die); computerScore += die; } while (computerScore <= 20 && die >=2 && die <=6 ); if (computerScore >=20) computerHold(); if (die == 1) switchTurn(); } The roll() method just simply has the previous line of code in it, "int die = (int)(6.0 * Math.random()) + 1;" i have tried

Could someone explain me the .getClass() method in java

霸气de小男生 提交于 2020-01-13 16:28:09
问题 I am currently taking a java class in university. This is my first programming class and I've stumbled on something that I just cannot understand. As i learned, there are two ways of comparing variables. The first is using the == , != , < , > , =< , >= signs for PRIMITIVE variables such as int,double,etc. and the second way is to use the .equals() method for reference type. Now here is my question: When I use the .getClass() method, I can compare two classes with the .equals() method and the