Why it is wrong when the number is 121

This are the codes to show it is a prime number or not.i don't know if i enter 121,it get wrong result.
//Java core packages
import java.awt.*;
//Java extension packages
import javax.swing.*;
public class P3 extends JApplet {
//initialize the mod result
int result = 0, //result after mod
ponumber, //number to loop
input; //the number to be mod
//initialize applet by obtaining valuse from user
public void init()
String number;
//get number
number = JOptionPane.showInputDialog( " Please enter number to confirm " );
//convert it to integer
input = Integer.parseInt( number );
}//end first method
//draw the result
public void paint( Graphics g )
for ( ponumber = input -1;ponumber >= 2;ponumber--) //begin loop
result = input % ponumber;
//if the number is 2,its result also 0,but 2 is a prime number
//so the input number should out of 2
if (( result == 0 )&&( input > 2))
g.drawString( " Number " + input + " is not a prime number ", 25, 25 );
else
g.drawString( " Number " + input + " is a prime number ", 25,25 );
}//end second method
} //end P3 class

It seems to me that your answer will always be that it is a prime number.
try somthing like this:
boolean prime = true;
for(ponumber = input-1;ponumber >=2;ponumber--)
if(input%ponumber!=0) prime = false;
if(prime)
//print prime
else:
//print not primeI haven't tested this, no time now, but there is a little difference between what I have and what you have. Try to see what that is and see if this works for you. I'll check back later.

Similar Messages

  • How To Get rid of Exponential format in datagridview when the number is very large

    When the number is very large like :290754232, I got 2.907542E +08. in datagridview cell
    I using vb.net , framework 2.0.
    how can I get rid of this format?
    Thanks in advance

    should I change the type of this column to integer or long ?
    The datagridview is binded to binding source and a list ( Of).
    Mike,
    I'll show you an example that shows the correct way to do this and a another way if you're stuck using strings in exponential format. The latter being the "hack way" I spoke about Friday. I don't like it, it's dangerous, but I'll show both anyway.
    In this example, I'm using Int64 because I don't know the range of yours. If your never exceeds Int32 then use that one instead.
    First, I have a DataGridView with three columns. I've populated the data just by creating longs starting with the maximum value in reverse order for 100 rows:
    The way that I created the data is itself not a great way (there's no encapsulation), but for this example "it'll do".
    Notice though that the third column (right-most column) isn't formatted at all. I commented out the part that does that so that I could then explain what I'm doing. If it works, it should look like the first column.
    The first column represents an actual Int64 and when I show the code, you can see how I'm formatting that using the DGV's DefaultCellStyle.Format property. That's how it SHOULD be done.
    The third column though is just a string and because that string contains a letter in it, Long.TryParse will NOT work. This is where the "hack" part comes in - and it's dangerous, but if you have no other option then ...
    You can see that now the third column matches the first column. Now the code:
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    With DataGridView1
    .AllowUserToAddRows = False
    .AllowUserToDeleteRows = False
    .AllowUserToOrderColumns = False
    .AllowUserToResizeRows = False
    .AlternatingRowsDefaultCellStyle.BackColor = Color.Aquamarine
    .ReadOnly = True
    .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    .MultiSelect = False
    .RowHeadersVisible = False
    .RowTemplate.Height = 30
    .EnableHeadersVisualStyles = False
    With .ColumnHeadersDefaultCellStyle
    .Font = New Font("Tahoma", 9, FontStyle.Bold)
    .BackColor = Color.LightGreen
    .WrapMode = DataGridViewTriState.True
    .Alignment = DataGridViewContentAlignment.MiddleCenter
    End With
    .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
    .ColumnHeadersHeight = 50
    .DataSource = Nothing
    .Enabled = False
    End With
    CreateData()
    End Sub
    Private Sub CreateData()
    Dim longList As New List(Of Long)
    For l As Long = Long.MaxValue To 0 Step -1
    longList.Add(l)
    If longList.Count = 100 Then
    Exit For
    End If
    Next
    Dim stringList As New List(Of String)
    For Each l As Long In longList
    stringList.Add(l.ToString("e18"))
    Next
    Dim dt As New DataTable
    Dim column As New DataColumn
    With column
    .DataType = System.Type.GetType("System.Int64")
    .ColumnName = "Actual Long Value (Shown Formated)"
    dt.Columns.Add(column)
    End With
    column = New DataColumn
    With column
    .DataType = System.Type.GetType("System.String")
    .ColumnName = "String Equivalent"
    dt.Columns.Add(column)
    End With
    column = New DataColumn
    With column
    .DataType = System.Type.GetType("System.String")
    .ColumnName = "Formated String Equivalent"
    dt.Columns.Add(column)
    End With
    Dim row As DataRow
    For i As Integer = 0 To longList.Count - 1
    row = dt.NewRow
    row("Actual Long Value (Shown Formated)") = longList(i)
    row("String Equivalent") = stringList(i)
    row("Formated String Equivalent") = stringList(i)
    dt.Rows.Add(row)
    Next
    Dim bs As New BindingSource
    bs.DataSource = dt
    BindingNavigator1.BindingSource = bs
    DataGridView1.DataSource = bs
    With DataGridView1
    With .Columns(0)
    .DefaultCellStyle.Format = "n0"
    .Width = 150
    End With
    .Columns(1).Width = 170
    .Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    .Enabled = True
    End With
    End Sub
    ' The following is what I commented
    ' out for the first screenshot. ONLY
    ' do this if there is absolutely no
    ' other way though - the following
    ' casting operation is NOT ADVISABLE!
    Private Sub DataGridView1_CellFormatting(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _
    Handles DataGridView1.CellFormatting
    If e.ColumnIndex = 2 AndAlso e.Value.ToString IsNot Nothing Then
    ' NOTE! The following is dangerous!
    ' I'm going to use coercion to force the
    ' string into a type long. TryParse will
    ' NOT work here. This can easily throw an
    ' exception if the string cannot be cast
    ' to a type long. I'm "depending on" the
    ' the string to cast. At the very least
    ' you might put this in a Try/Catch but
    ' that won't stop it from failing (if
    ' it doesn't work).
    Dim actualValue As Long = CType(e.Value.ToString, Long)
    Dim formattedValue As String = actualValue.ToString("n0")
    e.Value = formattedValue
    End If
    End Sub
    End Class
    Like I said, only use that hack way if there's no other option!
    I hope it helps. :)
    Still lost in code, just at a little higher level.

  • Knows someone absinthe? What can go wrong when the jailbreak? what is VPN?

    knows someone absinthe? What can go wrong when the jailbreak? what is VPN?

    philippwayne wrote:
    What can go wrong when the jailbreak?
    See this Apple doc:
    Unauthorized modification of iOS has been a major source of instability, disruption of services, and other issues

  • Why does Safari freeze when the cursor hovers across "Bookmarks"?

    Safari v 4.1
    Hi,
    When I move the cursor over "Bookmarks" in the menu at the very top of the window, Safari freezes for about 5 minutes. It can also freeze when the cursor is simply passing under the "Bookmarks". When I'm moving the cursor horizontally across the entire screen, I have to keep the cursor well below the top menu bar to avoid freezing Safari. Otherwise Safari is working OK. I often Force Quit" Safari when this happens, but if I wait, it will unfreeze.
    This is all about hovering, not clicking.
    Any suggestions as to why this is happening and how to fix it.
    Thanks, Rafael

    Hi Carolyn.
    First, about resetting. I've never done it before, and I recall hearing—but have no direct experience—that it practically wipes the slate clean. I've built a very sophisticated Bookmarks Bar and Bookmarks Menu, and because I'm a researcher, I never erase history. When I started using Safari a long time ago, I was told by Apple to regularly erase history. Then a couple of years ago I was told by someone I trust that it's OK to keep it.
    I regularly empty Cache and remove cookies.
    Are these the top 5 buttons?:
    1 Clear history
    2 Reset Top Sites
    3 Remove all webpage preview images
    4 Empty the cache
    5 Clear the Downloads window
    I got this list from Safari Help>Resetting Safari. I'm using Safari 4.1, but I noticed that this help page referred to Safari 5 in the 'Reset Top Sites' explanation: "Reset Top Sites: … Top Sites page reverts to showing the webpage previews displayed when you first installed Safari 5."
    As for the rest:
    2 Reset Top Sites—I’ve never made use of this
    3 Remove all webpage preview images—not familiar or I don’t recognize what it is.
    4 Empty the cache—Fine with that
    5 Clear the Downloads—window Fine with that
    I’m letting you know about these details before I proceed with your instructions.
    Thanks for responding,
    Rafael
    PS Since I'm asking about Bookmarks here, I've been meaning to find out something about my Safari Bookmarks.html that is exported, then backed up to one of my external HDs. If Safari or my computer crashes, and I re-install Safari, then import those bookmarks, are they re-created to look just as they do now in 'Show All Bookmarks'?
    I have some old bookmarks (or 'Favorites' I think they were called) that, when imported (in an html format?), appeared as a long list, rather than as a neatly tiered record of folders and files.

  • How to use JavaBeans when the number of inputs is variable

    I have a problem. The number of textboxes in a HTML form is read from a database. How can I avoid reentry from users? Is it possible to use JavaBeans or may be there is some other way? Thanks in advance.

    Well, I meant that when a Jsp page is generated the number of textboxes is read from the database. So it it is apriory unknown. But I have found a solution to this problem: create a bean of String type for each textbox. Thanks.

  • How to send multiple attachments when the number of attachment is known at

    I am creating an independent E-mail component for an n tire architecture. This component gets the email message and files_to_Attach as method parameters.
    Files to attach is inside an array list.
    So the number of files for attachment is known only at run time.
    How can I attach this files.
    If I use single instance of MimeBodyPart (ib side a Four or While loop), it attaches the last file several times.
    Please advise me on this

    hi
    some related links
    http://forum.java.sun.com/thread.jspa?threadID=684327&messageID=4429819
    http://www.jscape.com/articles/sending_email_attachments_using_java.html
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=45&t=003546
    http://www.dbforums.com/showthread.php?t=1059049
    http://www.experts-exchange.com/Programming/Programming_Platforms/Unix_Programming/Q_21072849.html

  • Why iTunes Stops Playing When The Microwave is On?

    Today I have noticed that my iTunes is disrupted when the Microwave is On. If the microwave can affect the transmission of data, etc. then I suspect this will also have some consequences in your personal health. Will appreciate if anyone could give me some advise and your experience with microwave operation and Wi-Fi signal disruption. Health consequences?
    Information about the equipment I'm using:
    iMac Intel.
    OS X Version 10.9.2
    Your comments on this subject will be appreciated.
    MadCat

    What you need to do is move your Mac and Microwave further apart from each other, and on a different electrical circuit, so there is no interference. It isn't anything affecting your personal health any more than standing in front of your Microwave oven waiting for the popcorn to be done. It is probably electrical field interference and related issues, though.

  • Why does Apple TV sons using in dorm keep saying password is wrong when the home Apple TV uses same password with no problem

    MY son is away at school and the Apple TV I got him to use keeps telling him his password is wrong.  This is the same password we use on the home Apple TV and he wants to be able use the movies, shows etc that have been purchased from this Apple ID.  Please help

    Most school's require a login to use the network, and the Apple TV has no browser to accomplish this task. It is likely not connected to the network, which is causing the error. Best to speak to the IT dept

  • How can I stop someone from receiving iMessages on their old disconnected iPhone, w'hich is still active in iMessage, when the number now belongs to someone else with a non apple device!?!

    To further clarify my dilemma ....
    A friend of mine just got a new phone number on her LG cell phone.
    When I try to text her, my messages are going to someone else's iPhone.
    The iPhone has been deactivated off the VZ cell network, but they are still using it on WIFI.
    They used to have this number on their iPhone, and it's still active in iMessage.
    So, when I try to send a text message to my friend on her LG, from my iPhone,
    they instead go to this total stranger, cuz they still have that number active in their iMessage account.
    This is a serious issue!!
    The only suggestion I get from apple support is to have my friend get a new number, or for me to turn off iMessage when I want to text her.
    Not really the optimum solution.
    Something really should be done to prevent this from happening!
    Strangers are effectively intercepting text messages!
    Help!?!

    Tell her to contact her carrier and get a new phone number.

  • Why features were removed when syn Number file from iMac to ipad?

    Can anyone advise me on this question?
    I am using Number on both iMac and ipad and usually update file on iMac with various feature such as cell merge, header and footer row, etc.
    However, this kind of stuff were removed after syn and open file in ipad. Why is that? Anything related to setting?

    Numbers for the iPad is a different app than the version for the Mac. because it is for a mobile device (iOS), its has less functionality.

  • Output number is wrong when inputing number w/commas

    I've been working on this code for less than a week and have been able to make it work like I need it to except when I input numbers with commas (the loan amount) or I'll get an error when I type in "%" for the interest. Any ideas on what I've done wrong to fix these two errors? I thought the while statement was the problem for the comma error, but that part was given to me so it shouldn't be wrong. Any and all help would be much appreciated. Thanks in advance.
    BTW, it compiles just fine and will do what I want it to if I leave off the commas and the "%" sign... but the instructions are to enter both the commas and "%" as part of the inputs.
    I think this is where the code goes awry... but I'm not sure.
              // Substrings
              principalAmount = principalAmount.substring(principalAmount.indexOf('$')+1);
              principalAmount = principalAmount.substring(principalAmount.indexOf(',')+1);
              interestAmount = interestAmount.substring(interestAmount.indexOf('%')+1);
              interestAmount = interestAmount.substring(interestAmount.indexOf('.')+1);
              // convert string to #
              principal = Double.parseDouble(principalAmount);
              interest = Double.parseDouble(interestAmount);
              interest = interest / 100;
              years = Integer.parseInt(yearsAmount);
              // While statement
              while (principalAmount.indexOf(',') >= 1)
                   principalAmount = principalAmount.substring(0,principalAmount.indexOf(','))
                   + principalAmount.substring(principalAmount.indexOf(',')+1);
              

    @flounder
    Isn't that what I'm doing by using the substrings? Sorry, I'm a bit confused on how to strip out and calling the parseDouble.
    @CaptainMorgan08
    I was told that by someone else... but I haven't learned what that is yet. In my book, that's in chapter 9, but I've only gotten to chapter 4...
    Message was edited by:
    Tsurara

  • Why does firefox crash when the internet connection is lost?

    We have been having trouble with our internet connection recently and firefox crashes whenever the connection is lost, but this didn't used to happen, so I was wondering why this was happening.

    If there is any intermittent issues or connection is lost you will revert to the menu, regardless. The 'apps' are fed via server and there is nothing stored on the unit, it simply caches when you are online.
    As for the initial wait time. That could be due to ISP throttling, interference, using another DNS
    Note: This is a user forum, there is no service provided here by Apple. If you wish to get official tech support you need to contact them.

  • Counter slows down when the number of the expected pulses don't arrive

    G'Day Everyone,
    I'm having a problem with some counter work I'm doing, and can't seem to work out where the problem lies. I'm using a NI-PCI-6602, and I setup the counter, send a couple of DIO lines high (this tells the attached custom electonrics to fire), and then clock the pulses that arrive. I'm looking for four pulses to come back (I set this using "Counter Buffer Config.vi" and look for them with "Counter Read Buffer.vi"), and it works really well when four pulses arrive. Unfortunately, sometimes the instrument may not send all of the four pulses (I occasionally get back 0, 1, 2 or 3 pulses). When this happens, my VI slows down remarkably - when all four are there I get in the order
    of 10ms response times, but if one or more are missing it slows down to approximately 1000ms. I've set the "time limit" input of "Counter Read Buffer.vi" to 10ms, but using the (often unpredictable) VI Profile utility, it seems that the hold up is either when I arm or disarm the counter using "Counter Control.vi". I've attached the VIs llb for your interest.
    Any help that you can give will be truly appreciated!
    cheers,
    Christopher
    Copyright © 2004-2015 Christopher G. Relf. Some Rights Reserved. This posting is licensed under a Creative Commons Attribution 2.5 License.
    Attachments:
    CounterIssues.zip ‏430 KB

    Thanks for the help everyone (especially Darren who guided me toward the solution) - the problem was a simple one, but I couldn't see the forest from the bush fires: the project is based on LabVIEW 5.1 (old project, no money - I'm sure you all know the deal!), and so a clean install gave the errors. It turns out that the board (6602) was released after LabVIEW 5.1 (and hence LabVIEW5.1's default NI-DAQ), so a fresh NI-DAQ install corrected any problems...
    thanks again!
    Christopher
    Copyright © 2004-2015 Christopher G. Relf. Some Rights Reserved. This posting is licensed under a Creative Commons Attribution 2.5 License.

  • I purchased Mac Pro in Aug 2013.  Why can't I get the Number, etc free?

    i purchased a new Mac book pro ( my first Apple / Mac) and now find out that Numbers, etc is free for those who bought in Oct?  How can I get a free copy also?

    I'm pretty new at this Mac stuff, but I went to the App store - downloaded OS X Mavericks , system showed it downloading and then applying, auto-rebooted automatically.  But now under 'Purchases' in the App store it has OS X Mavericks with a 'download' box highlighted.  I decided to download, same thing 2nd time.  Nothing shows under 'Updates',

  • Wrong page numer (1) when the numer of printed page is 2 using group

    I use crystal XI to print a document (facture) from a program.
    When the number of printed lines (details) is the max number is possible to print , the number of page (PageNumber) is wrong because the printed page is 2 (the second page is only a line of notes inserted in a group section).
    For the sotfware society of the program the problem is the printer driver but i have tested with more then one driver and the error is the same.
    what's the problem?
    Sorry! My english is not good.
    Thank you.

    If the page number is in the page header, and the page header prints on each page, then I cant see what the problem is.
    Perhaps it is a printer error.  Try a different printer and see if it happens.
    If a different printer is the same, try putting the page number in different areas of your report.
    If still no change, create a new test report and see if it happens there.

Maybe you are looking for

  • Downloading past music problem

    Does anybody know if they are limiting the time you download you past music. I got this message "This computer is already associated with an Apple ID. You can download past purchases on this computer with just one Apple ID every 90 days. This compute

  • Error while updating, now it will not turn on.

    My friend has had this problem, it is not mine, but she asked me to look into it for her. She was having troubles with her iPod Touch, such as when she was looking through the album view, it would stop playing the song that was currently playing and

  • Tax field table  in purchase order

    Hi, What is the table  of the tax details that appear in the  invoice tab of t-code ME23N. Thanks in Advance. Regard Sam.

  • Email Client in Photoshop Elements 11

    I do not get the option to select the email client.  It only gives me an @adobe.com email option.

  • Can my iBook G4 work on Wireless A Access Point?

    Is there anyway, aftermarket, via USB add on or something else that I can use to modify my iBook G4 to make it work on a Wireless A band network? Can't find anything about this on the internet. Any help would be greatly appreciated. Mike