Wednesday, March 18, 2020

The Hertz sprung-Russell Essays

The Hertz sprung-Russell Essays The Hertz sprung-Russell Essay The Hertz sprung-Russell Essay The Hertz sprung-Russell The chief sequence is a uninterrupted and typical set of stars that appear on secret plans of leading colour versus brightness. Stars on this set are known as main-sequence stars or dwarf stars. A star on the chief sequence is one that is bring forthing visible radiation and heat by the transition of H to helium by atomic merger in its nucleus. The Sun, along with the majority of the stars seeable to the bare oculus, are chief sequence stars. A star arrives on the chief sequence after it starts H combustion in its nucleus and remains there throughout its core-hydrogen-fusion stage. A star s place and length of stay on the chief sequence depend critically on mass. The most monolithic stars the hot, bluish-white O stars and B stars occur to the upper left and have main-sequence life-times of merely a few million or 10s of 1000000s if old ages. The least monolithic, hydrogen-burning stars, the ruddy midget, sit to the lower right and may stay on the chief sequence for 100s of one mi llion millions of old ages. With the exclusion of hypergiants, the brightest, largest sort of star. Supergiants have brightnesss of 10,000 to 100,000 solar brightnesss and radii of 20 to several hundred solar radii ( about the size of Jupiter s orbit ) . The two commonest types are ruddy supergiants, exemplified by Betelgeuse and Antares, and bluish supergiants, exemplified by Rigel. When a star of at least 15 solar multitudes exhausts the H in its nucleus, it foremost swells to go a ruddy giant. But when it reaches the phase of helium-to-carbon combustion, by the triple-alpha procedure, it expands to an even larger volume. This much brighter, but still reddened star is a ruddy supergiant. Through a vigorous leading air current, ruddy supergiants steadily lose their drawn-out ambiances and turn into smaller but much hotter bluish supergiants. A bluish supergiant may so develop a fresh distended envelope and revert to the ruddy supergiant stage. Both types, ruddy and bluish, can detonate as supernovae. This came as something of a surprise to uranologists, since leading development theory had long taught that supernovae ever come from the ruddy assortment. However, the great Supernova 1987A was found to hold had a bluish supergiant precursor. Supergiants are among the most monolithic stars. In the Hertzsprung-Russell diagram they occupy the top part of the diagram.

Monday, March 2, 2020

Using the Switch Statement for Multiple Choices in Java

Using the Switch Statement for Multiple Choices in Java If your Java program needs to make a choice between two or three actions, an if, then, else statement will suffice. However, the if, then, else statement begins to feel cumbersome when there are a number of choices a program might need to make. There are only so many else...if statements you want to add before the code begins to look untidy. When a decision across multiple options is required, use the switch statement. The Switch Statement A switch statement allows a program the ability to compare the value of an expression to a list of alternative values. For example, imagine you had a drop-down menu that contained the numbers 1 to 4. Depending on which number is chosen, you want your program to do something different: //lets say the user picks number 4int menuChoice 4;switch (menuChoice){ case 1: JOptionPane.showMessageDialog(null, You chose number 1.); break; case 2: JOptionPane.showMessageDialog(null, You chose number 2.); break; case 3: JOptionPane.showMessageDialog(null, You chose number 3.); break; //This option gets chosen because the value 4 matches the value of //the menuChoise variablecase 4:Â  JOptionPane.showMessageDialog(null, You chose number 4.);Â  break; default: JOptionPane.showMessageDialog(null, Something went wrong!); break;} If you look at the syntax of the switch statement you should notice a few things: 1. The variable containing the value that needs to be compared to is placed at the top, inside the brackets. 2. Each alternative option starts with a case label. The value to be compared against the top variable comes next, followed by a colon. For example, case 1: is the case label followed by the value 1 - it could just as easily be case 123: or case -9:. You can have as many alternative options as you need. 3. If you look at the above syntax, the fourth alternative option is highlighted - the case label, the code it executes (i.e., the JOptionPane) and a break statement. The break statement signals the end of the code that needs to be executed. If you look, youll see that every alternative option ends with a break statement. Its very important to remember to put in the break statement. Consider the following code: //lets say the user picks number 1int menuChoice 1;switch (menuChoice)case 1: JOptionPane.showMessageDialog(null, You chose number 1.);case 2: JOptionPane.showMessageDialog(null, You chose number 2.);break;case 3: JOptionPane.showMessageDialog(null, You chose number 3.); break;case 4: JOptionPane.showMessageDialog(null, You chose number 4.); break;default: JOptionPane.showMessageDialog(null, Something went wrong!); break;} What you expect to happen is to see a dialog box saying You chose number 1, but because there is no break statement matching the first case label, the code in the second case label also gets executed. This means the next dialog box saying You chose number 2 will also appear. 4. There is a default label at the bottom of the switch statement. This is like a safety net in case none of the values of the case labels match the value being compared with it. Its very useful to provide a way of executing code when none of the desired options are chosen. If you always expect one of the other options to be chosen, then you can leave out the default label, but to put one at the end of every switch statement you create is a good habit to get into. It might seem unlikely that it will ever be used but mistakes can creep into the code and it can help to catch an error. Since JDK 7 One of the changes to the Java syntax with the release of JDK 7 is the ability to use Strings in switch statements. Being able to compare String values in a switch statement can be very handy: String name Bob;switch (name.toLowerCase()){ case joe: JOptionPane.showMessageDialog(null, Good morning, Joe!); break; case michael: JOptionPane.showMessageDialog(null, Hows it going, Michael?); break; case bob: JOptionPane.showMessageDialog(null, Bob, my old friend!); break; case billy: JOptionPane.showMessageDialog(null, Afternoon Billy, hows the kids?); break; default: JOptionPane.showMessageDialog(null, Pleased to meet you, John Doe.); break;} When comparing two String values, it can be a lot easier if you make sure they are all in the same case. Using the .toLowerCase method means all the case label values can be in lowercase. Things to Remember About the Switch Statement The type of the variable to be compared against must be a char, byte, short, int, Character, Byte, Short, Integer, String, or enum type. The value next to the case label cannot be a variable. It has to be a constant expression (e.g., an int literal, a char literal). The values of the constant expressions across all the case labels must be different. The following would result in a compile-time error: switch (menuChoice){ case 323: JOptionPane.showMessageDialog(null, You chose option 1.); break; case 323: JOptionPane.showMessageDialog(null, You chose option 2.); break; There can only be one default label in a switch statement. When using an object for the switch statement (e.g., String, Integer, Character) make sure it is not null. A null object will result in a runtime error when the switch statement is executed.