<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title><![CDATA[Java Programming Forums - The Java Community - Loops & Control Statements]]></title>
		<link>http://www.javaprogrammingforums.com/</link>
		<description>for loops, while loops, switch, if-then-else..</description>
		<language>en</language>
		<lastBuildDate>Sat, 25 May 2013 10:04:50 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.javaprogrammingforums.com/images/misc/rss.png</url>
			<title><![CDATA[Java Programming Forums - The Java Community - Loops & Control Statements]]></title>
			<link>http://www.javaprogrammingforums.com/</link>
		</image>
		<item>
			<title>A while-loop is SUPPOSED to replace a substring</title>
			<link>http://www.javaprogrammingforums.com/loops-control-statements/29648-while-loop-supposed-replace-substring.html</link>
			<pubDate>Fri, 24 May 2013 22:42:15 GMT</pubDate>
			<description><![CDATA[I notice that my method doesn't work even though I tried to get it's while-loop set-up to do the following things: 
 
 
1. Have each token of a...]]></description>
			<content:encoded><![CDATA[<div>I notice that my method doesn't work even though I tried to get it's while-loop set-up to do the following things:<br />
<br />
<ol class="decimal"><li style="">Have each token of a string get put into another one</li><li style="">Replace each given-substring (string2) with it's assigned-replacement (string3) as the string's (string1) tokens pass by</li><li style="">Have it's final answer returned as a variable to the main-method</li></ol><br />
<br />
Here is my code that has each of it's parts with a comment...<br />
<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code Java:</div>
                <hr /><code class="bbcode_code"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">     <span style="color: #3F7F5F; font-style: italic;">// For the replacement of a substring with another one.</span>
     <span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> replaceSubstring<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> string1, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> string2, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> string3<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          Scanner keys <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Scanner<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">in</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
          <span style="color: #3F7F5F; font-style: italic;">// Use a StringTokenizer-object for breaking a string</span>
          <span style="color: #3F7F5F; font-style: italic;">// down to the point of finding that matching-substring</span>
          <span style="color: #3F7F5F; font-style: italic;">// in general.</span>
          <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringtokenizer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringTokenizer</span></a> numOne <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringtokenizer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringTokenizer</span></a><span style="color: #000000;">&#40;</span>string1, <span style="color: #0000ff;">&quot; &quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
          <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringtokenizer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringTokenizer</span></a> num1 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringtokenizer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringTokenizer</span></a><span style="color: #000000;">&#40;</span>string1, <span style="color: #0000ff;">&quot; &quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
          <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringtokenizer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringTokenizer</span></a> numWon <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringtokenizer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringTokenizer</span></a><span style="color: #000000;">&#40;</span>string1, <span style="color: #0000ff;">&quot; &quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
          <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> attacher <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
          <span style="color: #3F7F5F; font-style: italic;">// Find the substring with the while-loop.</span>
          <span style="color: #7F0055; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>numOne.<span style="color: #000000;">hasMoreTokens</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
          <span style="color: #000000;">&#123;</span>
               <span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>num1.<span style="color: #000000;">nextToken</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">==</span> string2<span style="color: #000000;">&#41;</span>
               <span style="color: #000000;">&#123;</span>
                    attacher <span style="color: #000000;">+=</span> string3<span style="color: #000000;">;</span>
               <span style="color: #000000;">&#125;</span>
               <span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>numWon.<span style="color: #000000;">nextToken</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">!=</span> string2<span style="color: #000000;">&#41;</span>
               <span style="color: #000000;">&#123;</span>
                    attacher <span style="color: #000000;">+=</span> numWon.<span style="color: #000000;">nextToken</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
               <span style="color: #000000;">&#125;</span>
          <span style="color: #000000;">&#125;</span>
&nbsp;
          <span style="color: #3F7F5F; font-style: italic;">// Finally, return the String-object.</span>
          <span style="color: #7F0055; font-weight: bold;">return</span> attacher<span style="color: #000000;">;</span>
     <span style="color: #000000;">&#125;</span></pre></div></code><hr />
</div> <br />
...and here is the output-part I want to avoid at runtime.<br />
<br />
<div style="margin:20px; margin-top:5px">

	<div class="smallfont" style="height:27px; background-image: url('http://www.javaprogrammingforums.com/images/console.png'); background-repeat: no-repeat;">&nbsp;</div>

	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 1px;
		border: 1px solid;
                border-color: #99BAF3;
                background-color:white;
                white-space:nowrap;
		width: 754px;
		height: auto;
                min-height:100px;
		text-align: left;
		overflow: auto"><br />
Exception in thread &quot;main&quot; java.util.NoSuchElementException<br />
        at java.util.StringTokenizer.nextToken(StringTokenize  r.java:349)<br />
        at MiscellaneousStr.replaceSubstring(MiscellaneousStr  .java:93)<br />
        at MiscellaneousSDemo.main(MiscellaneousSDemo.java:84  )<br />
<br></br></pre>
</div><br />
<br />
So as you can see, I have to avoid getting a message that refers to having no more elements in an enumeration.<br />
<br />
Any suggestions?</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/loops-control-statements/"><![CDATA[Loops & Control Statements]]></category>
			<dc:creator>SOG</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/loops-control-statements/29648-while-loop-supposed-replace-substring.html</guid>
		</item>
		<item>
			<title>String in java</title>
			<link>http://www.javaprogrammingforums.com/loops-control-statements/29458-string-java.html</link>
			<pubDate>Tue, 14 May 2013 22:06:52 GMT</pubDate>
			<description>Hello. 
I have a task and I need programming a small program like this; 
 
The program will count in a string text area how many used the same word....</description>
			<content:encoded><![CDATA[<div>Hello.<br />
I have a task and I need programming a small program like this;<br />
<br />
The program will count in a string text area how many used the same word.<br />
Example text<br />
<br />
&quot; A dog run out of home.When dog come back home he saw that there is another dog in home.&quot;<br />
<br />
In this text how many time word &quot;dog&quot; is used I have to count.But I dont know how can I make this program.I just think that I have to define a variable as this text value.And more  I dont know what to do.</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/loops-control-statements/"><![CDATA[Loops & Control Statements]]></category>
			<dc:creator>mockingbird</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/loops-control-statements/29458-string-java.html</guid>
		</item>
		<item>
			<title>Simple looping statement</title>
			<link>http://www.javaprogrammingforums.com/loops-control-statements/29159-simple-looping-statement.html</link>
			<pubDate>Sun, 05 May 2013 03:28:36 GMT</pubDate>
			<description>So I have a homework assignment where a program needs to be designed to allow the user to input the Number of bags sold (of coffee) as well as the...</description>
			<content:encoded><![CDATA[<div>So I have a homework assignment where a program needs to be designed to allow the user to input the Number of bags sold (of coffee) as well as the Weight per bag and output the information in a table as I've shown in my code and as I've tried to outline below:<br />
<br />
                                           Coffee Table<br />
Number of bags sold   Weight per Bag      Price per pound   Total Price    Price with Tax<br />
<br />
<br />
You have to calculate the total price using Total price= (unit weight) * num of units sold * 5.99<br />
<br />
You calculate price with tax using = (total price) + (total price) * 0.0725<br />
<br />
The only problem I'm having is that she's given use a table of values for Number of bags sold and weight per bag (that the user should be able to enter) and I know I have to incorporate a loop so that the values successfully output into the table. Here's my code:<br />
<br />
main method<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">import java.util.*;
public class CalcMain
{
    public static void main(String&#91;&#93; args){
        Scanner scanner = new Scanner(System.in);
        double weight, units, totalPrice, taxPrice, pricePerPound;
        System.out.println(&quot;\t\t\t\t&quot; + &quot;Coffee Table&quot;);
&nbsp;
        System.out.println(&quot;Enter Weight of Bag: &quot;);
        weight = scanner.nextDouble();
        System.out.println(&quot;Enter number of units: &quot;);
        units = scanner.nextDouble();
&nbsp;
        Calculator calculator = new Calculator();
        totalPrice = calculator.getTotalPrice(weight, units);
        pricePerPound = totalPrice/weight;
&nbsp;
        taxPrice = calculator.getTaxPrice(totalPrice);
&nbsp;
        System.out.println(&quot;Number of bags sold&quot; + &quot;\t&quot; + &quot;Weight per bag&quot; +
                           &quot;\t&quot; + &quot;Price per pound&quot; + &quot;\t&quot; + &quot;Total Price&quot; + &quot;\t&quot; + &quot;Price with tax&quot;);
        System.out.println(units + &quot;\t\t\t&quot; + weight + &quot;\t\t&quot; + &quot;$5.99&quot; + &quot;\t\t&quot; +
                           totalPrice + &quot;\t\t&quot; + taxPrice);
        }
}</pre></div></code><hr />
</div> <br />
calculator method<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">public class Calculator
{
    //set global variables
    public static final double PRICE = 5.99;
    public static final double TAX = 0.0725;
&nbsp;
    // instance variables - replace the example below with your own
    private double totalPrice;
    private double taxPrice;
&nbsp;
    /**
     * Constructor for the calculator setting total/tax prices at 0.
     */
    public Calculator()
    {
        // initialise instance variables
        totalPrice = 0.0;
        taxPrice = 0.0;
    }
&nbsp;
    /**
     * getTotalPrice and getTaxPrice methods
     */
    public double getTotalPrice(double weight, double units){
        totalPrice = weight * units * PRICE;
        return totalPrice;
    }
&nbsp;
    public double getTaxPrice(double totalPrice){
        taxPrice = totalPrice + (totalPrice * TAX);
        return taxPrice;
    }
}</pre></div></code><hr />
</div> <br />
I'm not sure in the least bit, how to incorporate a loop to allow multiple inputs of # of bags sold and Weight per bag and have it output as I've designated in the code. Could anyone possibly clue me in? I understand basic for-and-while loops.</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/loops-control-statements/"><![CDATA[Loops & Control Statements]]></category>
			<dc:creator>gta1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/loops-control-statements/29159-simple-looping-statement.html</guid>
		</item>
		<item>
			<title>Drawing Lines Loop</title>
			<link>http://www.javaprogrammingforums.com/loops-control-statements/29115-drawing-lines-loop.html</link>
			<pubDate>Fri, 03 May 2013 15:36:19 GMT</pubDate>
			<description>I am a beginner, I am in my first java course so please take it easy on me. But I have written this code drawing 15 lines. I am stuck on how to make...</description>
			<content:encoded><![CDATA[<div>I am a beginner, I am in my first java course so please take it easy on me. But I have written this code drawing 15 lines. I am stuck on how to make another loop to start the lines again in each corner.<br />
Here is my code thus far, and the result I am looking for. If anyone can help me or write show me the extra input needed to reach this picture please let me know.<br />
<br />
import java.awt.Graphics;<br />
import javax.swing.JPanel;<br />
import javax.swing.JFrame;<br />
<br />
public class DrawOneSetOfLines extends JPanel<br />
{<br />
    public static void main(String args[])<br />
    {<br />
        DrawOneSetOfLines panel = new DrawOneSetOfLines();<br />
<br />
       <br />
        JFrame application = new JFrame();<br />
<br />
        <br />
        application.setDefaultCloseOperation(JFrame.EXIT_O  N_CLOSE);<br />
<br />
        application.add(panel); <br />
        application.setSize(250, 250); <br />
        application.setVisible(true); <br />
    } <br />
<br />
    public void paintComponent(Graphics g)<br />
    {<br />
        <br />
        super.paintComponent(g);<br />
<br />
        int linesToDraw = 15;<br />
        int width = getWidth(); <br />
        int height = getHeight(); <br />
        int number, y, x, dy, dx;<br />
		  x = 0;<br />
		  y = height;<br />
		  number = 15;<br />
		  dx = width / number;<br />
		  dy = height / number;<br />
		  for( int i = 1; i &lt; number; i++ )<br />
		  {<br />
		  	x += dx;<br />
			y -= dy;<br />
			g.drawLine( 0, 0, x, y );<br />
<br />
        <br />
    } <br />
} <br />
}</div>


	<div style="padding:10px">

	

	

	
		<fieldset class="fieldset">
			<legend>Attached Images</legend>
			<ul>
			<li>
	<img class="inlineimg" src="http://www.javaprogrammingforums.com/images/attach/jpg.gif" alt="File Type: jpg" />
	<a href="http://www.javaprogrammingforums.com/attachments/loops-control-statements/2067d1367595339-drawing-lines-loop-first-jpg">First.jpg</a> 
(320.3 KB)
</li>
			</ul>
			</fieldset>
	

	

	</div>
]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/loops-control-statements/"><![CDATA[Loops & Control Statements]]></category>
			<dc:creator>02s2k</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/loops-control-statements/29115-drawing-lines-loop.html</guid>
		</item>
		<item>
			<title>Need help STUCK</title>
			<link>http://www.javaprogrammingforums.com/loops-control-statements/29091-need-help-stuck.html</link>
			<pubDate>Fri, 03 May 2013 10:54:52 GMT</pubDate>
			<description>I need to ask if the user wants to add another product receive a yes or no and run the loop again? Also I need to count the products and add the...</description>
			<content:encoded><![CDATA[<div>I need to ask if the user wants to add another product receive a yes or no and run the loop again? Also I need to count the products and add the prices together to figure an average?<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    private double computeAverageSales() {
        WebHost webHost;
        double average = 0;
        int counter = 0;
        double total = 0;
        boolean again = true;
        double webHostPrice = 0;
&nbsp;
        System.out.println(&quot;Enter 0 to end&quot;);
&nbsp;
&nbsp;
&nbsp;
&nbsp;
            System.out.println(&quot;Please enter the price of the new package: $&quot;);
            webHostPrice = scanner.nextDouble();
&nbsp;
            while (true){
            for (int i = 0; i &lt;= 0; i++) {
                if (webHostPrice == 0) {
                    break;
                } else if (webHostPrice &lt;= -1) {
                    System.out.println(&quot;Please enter a positive number!&quot;);
                } else if (webHostPrice &gt;= 500) {
                    System.out.println(&quot;Are you sure that seems a little high!&quot;);
                } else if (webHostPrice == 0){
                break;
            }   
&nbsp;
                System.out.println(&quot;Please enter the product ID &quot;);
                int webHostId = scanner.nextInt();
                if (webHostId &lt;= -1) {
                    System.out.println(&quot;Please enter a positive number!&quot;);
&nbsp;
                } else if (webHostId &gt; 10000) {
                    System.out.println(&quot;Sorry please enter a valid ID number&quot;);
&nbsp;
                } else if (webHostId == 0) {
                    break;
                } 
&nbsp;
                System.out.println(&quot;What is the product name: &quot;);
                String webHostName = scanner.next();
&nbsp;
                if (webHostName == null) {
                    System.out.println(&quot;Please enter a valid Product Name!&quot;);
&nbsp;
                }
                 if (webHostName.equals(&quot;end&quot;)) {
                    break;
                }
&nbsp;
&nbsp;
&nbsp;
                System.out.println(&quot;Please enter the required Bandwidth needed for your site? &quot;);
                double webHostBandwidth = scanner.nextDouble();
                if (webHostBandwidth &lt;= -1) {
                    System.out.println(&quot;Please enter a positive number!&quot;);
                    webHostBandwidth = scanner.nextDouble();
                    ///LOOK  Here's another INFINITE LOOP... This while will never quit
                }
                else if (webHostBandwidth &gt; 10000000) {
                    System.out.println(&quot;Please enter a vaild number!&quot;);
&nbsp;
                }
                else if (webHostBandwidth == 0) {
                    break;
                }
&nbsp;
&nbsp;
                System.out.println(&quot;How many FTP accounts do you need? &quot;);
                int webHostFtp = scanner.nextInt();
                if (webHostFtp &lt;= -1) {
                    System.out.println(&quot;Please enter a positive number!&quot;);
&nbsp;
                    ///LOOK  And, another INFINITE LOOP !!
                }
                else if (webHostFtp &gt; 120) {
                    System.out.println(&quot;Please enter a valid number!&quot;);
&nbsp;
                }
                else if (webHostFtp == 0) {
                    break;
                }
&nbsp;
&nbsp;
                System.out.print(&quot;How many email accounts do you need? &quot;);
                int webHostMail = scanner.nextInt();
                if (webHostMail &lt;= -1) {
                    System.out.println(&quot;Please enter a positive number!&quot;);
&nbsp;
                    ///LOOK  And still another INFINITE LOOP !!
                }
                else if (webHostMail &gt; 225) {
                    System.out.println(&quot;Please enter a valid number!&quot;);
&nbsp;
                }
                else if (webHostMail == 0) {
                    break;
                }
&nbsp;
                System.out.print(&quot;What is your domain name? &quot;);
                String webHostDomain = scanner.next();
                webHostDomain = webHostDomain.trim();
                if (webHostDomain.length() &lt; 0) {
                    System.out.println(&quot;Please enter a valid domain name!&quot;);
&nbsp;
                    webHostDomain = webHostDomain.trim();
                }
                else if (webHostDomain.equals(&quot;0&quot;)) {
                    break;
                }
&nbsp;
                System.out.println(&quot;Would you like to add another product? &quot;);
&nbsp;
&nbsp;
&nbsp;
            } // end for statement
            average = total / (counter - 1);
            return average;
            } // end while statement
    }</pre></div></code><hr />
</div> <br />
I know the code is messing but that is because I have worked 4 days on this I am a newbie any suggestions is much appreciated!</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/loops-control-statements/"><![CDATA[Loops & Control Statements]]></category>
			<dc:creator>mstratmann</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/loops-control-statements/29091-need-help-stuck.html</guid>
		</item>
		<item>
			<title>What is this code doing?</title>
			<link>http://www.javaprogrammingforums.com/loops-control-statements/28992-what-code-doing.html</link>
			<pubDate>Wed, 01 May 2013 19:03:09 GMT</pubDate>
			<description><![CDATA[public static long powMod2_32(int prime, int number) { 
        int answer2 = 1; 
        int p = prime; 
        for (int n = number; n > 0; n >>>=...]]></description>
			<content:encoded><![CDATA[<div>public static long powMod2_32(int prime, int number) {<br />
        int answer2 = 1;<br />
        int p = prime;<br />
        for (int n = number; n &gt; 0; n &gt;&gt;&gt;= 1) {<br />
            if ((n &amp; 1) != 0)<br />
                answer2 *= p;<br />
            p *= p;<br />
        }<br />
        return answer2 &amp; 0xFFFFFFFFL;<br />
    }<br />
<br />
I'm not too advanced with java.  I sort of understand what this block of code is doing, but not completely unfortunately.  Can someone tell me what it's doing?  Thanks!!</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/loops-control-statements/"><![CDATA[Loops & Control Statements]]></category>
			<dc:creator>linzylu1190</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/loops-control-statements/28992-what-code-doing.html</guid>
		</item>
		<item>
			<title>Making a countdown timer using the currentTimeMillis method</title>
			<link>http://www.javaprogrammingforums.com/loops-control-statements/28948-making-countdown-timer-using-currenttimemillis-method.html</link>
			<pubDate>Tue, 30 Apr 2013 09:15:38 GMT</pubDate>
			<description><![CDATA[Hey guys,  
 
Recently I made the decision to learn Java programming on my own (I only bought a book, no course). So far I've covered the following...]]></description>
			<content:encoded><![CDATA[<div>Hey guys, <br />
<br />
Recently I made the decision to learn Java programming on my own (I only bought a book, no course). So far I've covered the following relevant topics:<br />
-Elementary Programming: Identifiers, Variables, Data types...<br />
-Selections: boolean, if (else if, else) statements, logical operators, switch statements...<br />
-Loops: while, do-while, for, nested loops, keywords break and continue... (=&gt; Currently doing the exercises of this chapter).<br />
<br />
In one of the last exercises of the latter chapter I'm asked to make a countdown timer. The only method to capture time the book has covered yet is the currentTimeMillis method in the System class.<br />
I'm aware this problem probably can be solved in an easier and more efficient way using the Timer class, but imagine I follow the book strictly and I have never heard of it.<br />
<br />
So far I have tried a number of things, without succes obviously, this is the best I came up with: <br />
<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code Java:</div>
                <hr /><code class="bbcode_code"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Scanner</span><span style="color: #000000;">;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">class</span> Exercise4_43 <span style="color: #000000;">&#123;</span>
		<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		Scanner input <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Scanner<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">in</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">print</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Enter the number of seconds: &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> interval <span style="color: #000000;">=</span> input.<span style="color: #000000;">nextInt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> startTime <span style="color: #000000;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">currentTimeMillis</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> endTime <span style="color: #000000;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">currentTimeMillis</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> <span style="color: #000000;">&#40;</span>interval <span style="color: #000000;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
		<span style="color: #7F0055; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">currentTimeMillis</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&lt;</span> endTime<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>endTime <span style="color: #000000;">-</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">currentTimeMillis</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">%</span> <span style="color: #cc66cc;">1000</span> <span style="color: #000000;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
				<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>endTime <span style="color: #000000;">-</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">currentTimeMillis</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">/</span> <span style="color: #cc66cc;">1000</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> <span style="color: #0000ff;">&quot; seconds remaining.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Stopped.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></code><hr />
</div> <br />
When I run the program and e.g. enter 10 as input I get the following output:<br />
<br />
10 seconds remaining<br />
//1 second later<br />
9 seconds remaining<br />
9 seconds remaining<br />
9 seconds remaining<br />
9 seconds remaining<br />
//another second later<br />
8 seconds remaining<br />
8 seconds remaining<br />
8 seconds remaining<br />
8 seconds remaining<br />
//another second later<br />
7 seconds remaining<br />
7 seconds remaining<br />
7 seconds remaining<br />
7 seconds remaining<br />
<br />
....<br />
<br />
0 seconds remaining<br />
Stopped.<br />
<br />
Can someone please give me a hint so I can solve this problem? (Please, don't give a possible solution, if I can't solve the problem myself I miss the opportunity to acquire some extra insight in this kind of problems).<br />
Thanks in advance!<br />
<br />
Cheers<br />
Michael</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/loops-control-statements/"><![CDATA[Loops & Control Statements]]></category>
			<dc:creator>Michael_D</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/loops-control-statements/28948-making-countdown-timer-using-currenttimemillis-method.html</guid>
		</item>
		<item>
			<title>Dealing With Overflow?</title>
			<link>http://www.javaprogrammingforums.com/loops-control-statements/28944-dealing-overflow.html</link>
			<pubDate>Tue, 30 Apr 2013 06:21:41 GMT</pubDate>
			<description><![CDATA[Hi,  
 
Does anyone know a short code that prevents overflow when using encryption?  I don't understand what my professor means by this.  I asked him...]]></description>
			<content:encoded><![CDATA[<div>Hi, <br />
<br />
Does anyone know a short code that prevents overflow when using encryption?  I don't understand what my professor means by this.  I asked him if we could round or just cut off so many numbers and he said no to both...?  So maybe someone else understands what he's asking?  I know we need to use a loop which is why I posted it into this forum.  Thanks!</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/loops-control-statements/"><![CDATA[Loops & Control Statements]]></category>
			<dc:creator>linzylu1190</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/loops-control-statements/28944-dealing-overflow.html</guid>
		</item>
	</channel>
</rss>
