Results 1 to 3 of 3
  1. #1
    tm02943 is offline Member
    Join Date
    Mar 2011
    Rep Power

    Exclamation Need help almost finished problem thats due

    Ok so the program I am writing is-
    a program that stores a number in an integer variable x. The program then prints all the numbers from x to 1 that ends with either 3 or 5 or 7.

    So far I have-

    import javax.swing.JOptionPane;

    public class C2{

    public static void main ( String [] a)
    String T = JOptionPane.showInputDialog(null, "Insert Number Here:");
    int x = Integer.parseInt(T);

    int counter= x;

    while (counter>=1)


    The If statement is wrong, I know that mod 10 is how you get the last digit of a number but i cannot use it in my program correctly.

    Please help

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    "if" evaluates boolean values (true/false). What does the "%" return? Is this a boolean? If not, what do you need to do with that result to get a boolean result that makes sense?

  3. #3
    nathic is offline Member
    Join Date
    Oct 2010
    Rep Power


    Don't parse it to an integer :D just check if the last Character equals "3","5" or "7" (notice that 3,5,7 are Strings)

    you can get the last character of a String with YourString.charAt(YourString.length()-1)

    I know there are better solutions but it'll do for this job.
    Last edited by nathic; 03-22-2011 at 08:14 AM.

Similar Threads

  1. How do I know that byte of stream is finished?
    By mani_minhaj in forum New To Java
    Replies: 2
    Last Post: 02-26-2010, 12:08 PM
  2. Finished Product: What now?
    By Unome in forum Java Applets
    Replies: 5
    Last Post: 02-11-2009, 10:41 AM
  3. How to construct my finished program?
    By matpj in forum New To Java
    Replies: 0
    Last Post: 01-14-2009, 05:37 PM
  4. finished paint!
    By diggitydoggz in forum New To Java
    Replies: 3
    Last Post: 01-04-2009, 10:33 AM
  5. How to run a code when a download is finished
    By aneesahamedaa in forum New To Java
    Replies: 4
    Last Post: 10-14-2008, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts