Let's assume I have got a List of Flight Objects  public class Flight {     private int passengers;     private int price     ...      //getters and Setters }  List&lt;Flight&gt; flightList = new ArrayList&lt;Flight&gt;();   Now i need to accumulate price per passenger and the Price, because I have to be able to proceed both informations later on. so I would create two methods:  public int calculatePrice(List&lt;Flight&gt; flightList) {     int price = 0;     for (Flight flight : flightList) {         price = price + flight.getPrice();     }     return price; }  public int calculatePricePerPassengers(List&lt;Flight&gt; flightList) {     int pricePerPassenger = 0;     for (Flight flight : flightList) {         pricePerPassenger = (pricePerPassenger) + (flight.getPrice() / flight.getPassgers());     }     return pricePerPassenger; }   I have got like 4-5 methods of the same type. I am not sure whether there is too much redundancy, because I call the for loop 4-5 Times and I could easily do all the operations in one for loop, but that would have the effect of multiple return values. So is this the appropriate way ? (just a dummy example)
I want to return two objects from a Java method and was wondering what could be a good way of doing so?  The possible ways I can think of are: return a HashMap (since the two Objects are related) or return an ArrayList of Object objects.  To be more precise, the two objects I want to return are (a) List of objects and (b) comma separated names of the same.  I want to return these two Objects from one method because I dont want to iterate through the list of objects to get the comma separated names (which I can do in the same loop in this method).  Somehow, returning a HashMap does not look a very elegant way of doing so.
Drop "not constructive", combine "noisy", reword "rude" and "other" comment flags Cardinality of cartesian product of an infinite set with N Here the problem 1.4.26 from Sohrab, Basic Real Analysis  Duplicate  This are not duplicate of this question:    the answer gives no proof  despite the title is not really connected  only finite set   Problem  Show that, if $A$ is an infinite set, then $|A\times\mathbb{N}|=|A|$. Hint: Let $\mathcal{F}$ denote the set of all bijective maps $f:S\times\mathbb{N}\to S$, where $S\subset A$. Since $|\mathbb{N}\times\mathbb{N}|=|\mathbb{N}|$, we have $\mathcal{F}\neq \varnothing$ (Why?) Show that Zorn's Lemma can be applied in $\mathcal{F}$ to produce a maximal bijection $h:B\times\mathbb{N}\to B$, with $B\subset A$, and that we must have $B=A$, by examining the cases where $S\setminus B$ is finite or infinite.  Proof  Let $\mathcal{F}$ denote the set of all bijective maps $f:S\times\mathbb{N}\to S$, where $S\subset A$. Since $|\mathbb{N}\times\mathbb{N}|=|\mathbb{N}|$ (see exercise 1.4.10(i)), we have $\mathcal{F}\neq \varnothing$ (From Exercise 1.4.22(d) we know that for a infinite set $A$, we have $|A|\geq\aleph_0$, and $|\mathbb{N}|=\aleph_0$, thus there is an injection from $g:\mathbb{N}\to A$, and, by defining $S:=g(\mathbb{N})\subset A$, we get a bijective map (composition of two bijective maps) $S\times\mathbb{N}\to\mathbb{N}\times\mathbb{N}\to\mathbb{N}\in\mathcal{F}$).  If we consider the inclusion as partial order, then every chain $S_i\subset A$, $i\in I$, has $A$ as upper bound and applying Zorn's Lemma, we get the existence of a maximal $\bar{S}$ and hence a bijection $h:\bar{S}\times\mathbb{N}\to\bar{S}$, with $\bar{S}\subset A$.  Now we prove that $\bar{S}=A$. $R:=A\setminus \bar{S}$. $\bar{S}$ is infinite, since the example of element of $\mathcal{F}$, that we gave above is bijective to $\mathbb{N}$. We have to do this. The second is trying to follow the hint and is incomplete:   Consider that $A\neq\bar{S}$, then there is $r\in R:=A\setminus\bar{S}$. We chose an element $s\in\bar{S}$ and define the bijection $h':\bar{S}\cup\{r\}\times\mathbb{N}\to \bar{S}\cup\{r\}$ as follow  $h'(a,n)=\begin{cases}h(s,2n-1)&amp;\text{for }a=s\\ r&amp;\text{for }a=r,n=1\\ h(s,2n-2)&amp;\text{for }a=r,n\neq 1\\ h(a,n)&amp;\text{otherwise}\end{cases} $  Since $\bar{S}\subsetneq \bar{S}\cup\{r\}$ we get a contradiction to the maximality of $\bar{S}$. Now either $R$ is finite or infinite. 1) $R$ finite, let say $R=\{r_1,\cdots,r_n\}$. Then chose $n$ elements $s_1,\cdots,s_n\in\bar{S}$ and we define the bijection $h':A\times\mathbb{N}\to A$ as follow $h'(a,n)=\begin{cases}h(a,2n-1)&amp;\text{for }a\in\{s_1,\cdots,s_n\}\\ a&amp;\text{for }n=1,a\in\{r_1,\cdots,r_n\}\\ h(s_i,2n-2)&amp;\text{for }a=r_i\\ h(a,n)&amp;\text{otherwise}\end{cases}$  In case $n&gt;0$ we get a contradiction with $\bar{S}$ being the maximal element.   Thus we have only to exclude the case 2) $R$ infinite. HOW TO DO THAT?   Question  Above I tried two proofs. The first part is the same. The two second parts are given by the two bullets.  The second proof tries to follow the hint.  My questions are:   - Is my proof correct?   - In which direction should go the proof from the hint? I am using Google Chrome 48.0 32-bit. Today when I launched Google Chrome, I got this message:    This computer will soon stop receiving Google Chrome updates because this Linux system will no longer be supported   I thought Ubuntu 14.04 is supported for five years, what's exactly happening here?  And on 64-bit Ubuntu, I get an error from Update Manager and apt-get update:  Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release  Unable to find expected entry 'main/binary-i386/Packages' in Release file (Wrong sources.list entry or malformed file)   Some index files failed to download.   They have been ignored, or old ones used instead. How are constraint forces represented in Lagrangian mechanics? Complex number identity by trigonometry Show that $\lvert e^{i\theta} - 1\rvert = 2\lvert\sin(\theta/2)\rvert$ by using the geometry of the triangle with vertices 0, 1, and the midpoint of the line joining 0 and $e^{i\theta}$.  I have been able to show this identity through other means, however I am stuck on how to utilize this particular triangle. IBus methods do not show up in text entry settings I installed both Korean and Japanese using the Language Support window, and expected Korean (Hangul) and Japanese (Anthy) to show up in the input sources for Text Entry Settings (having both packages installed). However, neither shows up. I have a 4GB DDR3 800Mhz recently I installed another 4GB. It turns out it's  DDR3 667MHz. Does it really matter I should own both rams 800MHz?    Slot1 shows recent RAM installation. ALSO I don't know if this is 1600MHz (it shows 800x2 and 667x2 for other) or just 800MHz ram. So, I have proven already that every open set in $\mathbb{R}$ can be written as a countable union of disjoint open intervals; i.e., that $\mathcal{O} = \bigcup_{i=1}^\infty (a_{x_i}, b_{x_i})$.  Now, consider the closed interval $\left [ a + \frac{1}{n}, b - \frac{1}{n}\right ] \subset (a, b)$.  Since the midpoint of $(a,b)$ is $\frac{b-a}{2}$, we need $\displaystyle n &gt; \frac{2}{b-a}$.  Otherwise, $\displaystyle a + \frac{b-a}{2} = a + \frac{1}{ \frac{2}{b-a}} = b - \frac{1}{ \frac{2}{b-a}} = b - \frac{b-a}{2}$, and our interval will be degenerate.  Note that $\forall (a,b) \in \mathcal{O}$,   $\displaystyle \bigcup_{n = \frac{b-a}{2}+1}^{\infty} \left[ a + \frac{1}{n}, b - \frac{1}{n} \right] = (a,b)$.  So, we have $\displaystyle \mathcal{O} = \bigcup_{i=1}^\infty \left ( \bigcup_{n = \frac{b-a}{2} + 1}^\infty \left[ a_{x_i}+\frac{1}{n}, b_{x_i}-\frac{1}{n} \right] \right)$.  But, I don't like this. It looks like I'm still just taking a union of open sets.  Please help me get this to look like the union of closed sets.  (For unbounded intervals, I know what to do - it should follow from this relatively easily). Why is "union" an exception to the "a/an" rule? I'm a bachelor student majoring in math, and pretty interested in physics. I would like a book to study for classical mechanics, that will prepare me to work through . What books would be good for a beginner? Count number of increasing functions, nondecreasing functions $f: \{1, 2, 3, \ldots, n\} \to \{1, 2, 3, \ldots, m\}$, with $m \geq n$. I stumbled upon a question given like:  Let $m$ and $n$ be two integers such that $m \geq n \geq 1$.   Count the number of functions $$f: \{1, 2, · · · , n\} \to \{1, 2, · · · , m\}$$ of the following two types:  (a) strictly increasing; i.e., whenever $x &lt; y, f(x) &lt; f(y)$, and  (b) non-decreasing; i.e., whenever $x &lt; y, f(x) \leq f(y)$.  I tried in the following way.  For (a). We can say $f(n)&gt;f(n-1)$ AND $f(n)&gt;f(n-2) \ldots f(n)&gt;f(1)$ (total $n-1$ elements)  Similarly for $f(n-1)&gt;f(n-2), f(n-1)&gt;f(n-3) \ldots f(n-1)&gt;f(1)$ (total $n-2$ elements)...  and $f(2)&gt;1$  Like this $$(n-1) + (n-2) + \ldots + (1) = \frac{n(n-1)}{2}$$  Is this correct?  For (b). Since there's equality, it will be $$n + (n-1) + ... (1) = \frac{n(n+1)}{2}$$  Is my approach correct? Any help is appreciated. Thanks in advance. Change footer in beginning of chapters I want the footer of all pages to be "Page N°X" on the right. I used this:  \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} % clear all header and footer fields \fancyhead[R]{\leftmark} \fancyfoot[R]{\footnotesize Página N$^\circ$ \thepage\ } \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt}   It works on every page but the chapter beginning ones. I'm trying to simulate a media key press using a custom shortcut.  So far, I've been able to achieve the simulation I need using the command:  xdotool key XF86AudioPlay   It works perfectly, it pauses or starts the music player every time it is run.  The problem comes when trying to run it as a shortcut.  First I tried to run an alias with a custom shortcut, but it did not work.  As explained on :     The commands run by keyboard bindings are not parsed via a shell. Your best bet is to create a directory bin in your homedir.   Next I created the suggested script and named it simplay:  #!/bin/sh xdotool key XF86AudioPlay   It is located inside a bin folder which is part of the PATH, this works fine and can be run from any location.  When trying to create the Custom Shortcut, I was unable to get it to execute, the configuration is the following:  Name: test Command: simplay  Shortcut: Ctrl+Alt+R   After searching a bit more I found another way to execute the shortcut:  gnome-terminal -e simplay   I tried it on a terminal and noticed that when executing it it would rapidly open a new terminal window, execute the child process, pausing the music and immediately close the window.  I changed the command on the shortcut and when hitting it I noticed the same behavior opening a terminal and immediately being closed but this time the child process did not pause the music, which makes me think that the script has been called on all my previous attempts but it is somehow not being able to execute.  How can I solve this problem according to your knowledge? The product of a normal and Rademacher variables, independent from each other Let $X\sim N(0,1)$ and let $Z$ be a random variable independent of $X$ such that:  \begin{equation} \Pr(Z=z) = \begin{cases} \frac{1}{2} &amp; \mbox{if $z = -1$ or $z=1$}, \\ \\ 0 &amp; \mbox{otherwise}. \end{cases} \end{equation}   Define $Y = ZX$. Show that $Y \sim N(0,1)$. Determine $\operatorname{Cor}(X,Y)$. Are $X$ and $Y$ independent?   Progress:  I'm basically stuck at the beginning. I got as far as $P(ZX &lt; y) = P(Z &lt; y/X)$, which I'm not even sure is correct. I'm also not clear on what it means by defining $Y = ZX$ - does it mean I need to state the probability density function or something? And how do I show that $Y \sim N(0,1)$? Which configuration of armor enchantments gives maximum protection? Batch/Multi rename only files with a specific number range I have a situation where I have the following:  file01.ext . . . file99.ext file100.ext . . .   And I want to (using rename ) insert the '0' for the files 01-99 (so that they become 000-099) but not modify files larger than 100. Which expression should I use and what is a good source on learning regular expressions such as these?   On Windows I would have used Total Commander's multi rename function which has a very simple renaming syntax. Are there some good alternatives for that tool (multi-rename) for Ubuntu? I have been working on this exercise for a while now. It's in B.L. van der Waerden's Algebra (Volume I), page $19$. The exercise is as follows:     The order of the symmetric group $S_n$ is $n!=\prod_{1}^{n}\nu$. (Mathematical induction on $n$.)   I don't comprehend how we can logically use induction here. It seems that the first step would be proving $S_1$ has $1!=1$ elements. This is simply justified: There is only one permutation of $1$, the permutation of $1$ to itself.  The next step would be assuming that $S_n$ has order $n!$. Now here is where I get stuck. How do I use this to show that $S_{n+1}$ has order $(n+1)!$?  Here is my attempt: I am thinking this is because all $n!$ permutations of $S_n$ now have a new element to permutate. For example, if we take one single permutation $$ p(1,\dots,n) = \begin{pmatrix} 1 &amp; 2 &amp; 3 &amp; \dots &amp; n\\ 1 &amp; 2 &amp; 3 &amp; \dots &amp; n \end{pmatrix} $$ We now have $n$ modifications of this single permutation by adding the symbol $(n+1)$:  \begin{align} p(1,2,\dots,n,(n+1))&amp;= \begin{pmatrix} 1 &amp; 2 &amp; \dots &amp; n &amp; (n+1)\\ 1 &amp; 2 &amp; \dots &amp; n &amp; (n+1) \end{pmatrix}\\ p(2,1,\dots,n,(n+1))&amp;= \begin{pmatrix} 1 &amp; 2 &amp; \dots &amp; n &amp; (n+1)\\ 2 &amp; 1 &amp; \dots &amp; n &amp; (n+1) \end{pmatrix}\\ \vdots\\ p(n,2,\dots,1,(n+1))&amp;= \begin{pmatrix} 1 &amp; 2 &amp; \dots &amp; n &amp; (n+1)\\ n &amp; 2 &amp; \dots &amp; 1 &amp; (n+1) \end{pmatrix}\\ p((n+1),2,\dots,n,1)&amp;= \begin{pmatrix} 1 &amp; 2 &amp; \dots &amp; n &amp; (n+1)\\ (n+1) &amp; 2 &amp; \dots &amp; n &amp; 1 \end{pmatrix} \end{align}  There are actually $(n+1)$ permutations of that specific form, but we take $p(1,\dots,n)=p(1,\dots,n,(n+1))$ in order to illustrate and prove our original statement. We can make this general equality for all $n!$ permutations: $p(x_1,x_2,\dots,x_n)=p(x_1,x_2,\dots,x_n,x_{n+1})$ where $x_i$ is any symbol of our finite set of $n$ symbols and $x_{n+1}$ is strictly defined as the symbol $(n+1)$.  We can repeat this process for all $n!$ permutations in $S_n$. This gives us $n!n$ permutations. Then, adding in the original $n!$ permutations, we have $n!n+n!=(n+1)n!=(n+1)!$. Consequently, $S_n$ has order $n!$.  How is my reasoning here? Furthermore, is there a more elegant argument? I do not really see my argument here as incorrect, it just seems to lack elegance. My reasoning may well be very incorrect, however. If so, please point it out to me. What are the grammatical rules determining whether to use "which" or "what"? What are the grammatical rules determining whether to use which or what?  I usually go by intuition. It's "What car are you looking at?" and "What bicycle do you like most?" but "Which song did you sing?" Quite often, I don't know whether to use what or which.  How can I tell? Why ZSH ends a line with a highlighted percent symbol? I've noticed this on occasion with a variety of applications. I've often thought it was because the output was cancelled early (ctrl+c, for example) or something similar, and zsh is filling in a new line character. But now curiosity has gotten the best of me, since it doesn't seem to do this in bash.   zsh    bash    The Sequence program is something I pulled from a book while reading on Java certifications and just wanted to see if it would compile and run. I did notice that it does not use the println() method from the System.out package/class. Instead it uses plain old print().  Is the lack of a new line character the reason I get this symbol? Why is the node editor showing different kinds of nodes?