Results 1 to 8 of 8
  1. #1
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Help with While Statement Structure

    My main problem is that I get an error for incompatable types where is says I can't mix boolean and int, but im dividing a number which is set as an integer by an integer so Im lost.

    Java Code:
     import javax.swing.*;
    public class Exercise6_8 {
        
        public static void main(String[] args) {
    	
        int number;
       
        number = Integer.parseInt(
        	JOptionPane.showInputDialog("Enter thy number to see if it is prime:"));
        	
        
       while (number % 1 && number % number){
        	
        
        	System.out.println("it is a prime number");
        	System.exit(0);
        }
        	System.out.println("NO");
        	
        	
        	
        }
        
    }
    Last edited by easyeatlanta; 03-19-2013 at 03:42 PM.

  2. #2
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with While Statement Structure

    line 12 to be specific is where my problem is

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Help with While Statement Structure

    The result of a % call is an int, not a boolean.
    You need a boolean in a while.
    Please do not ask for code as refusal often offends.

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    6

    Default Re: Help with While Statement Structure

    Compiler:
    while (boolean){

    You:
    while (int){
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with While Statement Structure

    So i started over on this cause it was off here is what I now have

    Java Code:
     import javax.swing.*;
    public class Exercise6_8 {
        
        public static void main(String[] args) {
    	
        String numStr;
         int number;
         String numResult;
       
        numStr = JOptionPane.showInputDialog(null, "Enter a number.");
         number = Integer.parseInt(numStr);
        	
        
       while (isPrimeNumber(number)){
        	numResult = number + "is a prime number";
       }
        	
        	System.out.println(numResult);
        	
        static boolean isPrimeNumber(int pn){
         	return(pn%pn == 0) || (pn%1 == 0);	
        }
        
    }

  6. #6
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with While Statement Structure

    im getting an illegal start of expression for my last lines where is says static boolean

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    6

    Default Re: Help with While Statement Structure

    Your isPrimeNumber method cannot be inside the main method.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with While Statement Structure

    alright thanks for the help fixed it and now its working

Similar Threads

  1. Replies: 3
    Last Post: 11-19-2012, 08:12 PM
  2. Replies: 2
    Last Post: 03-26-2012, 04:27 PM
  3. Use if then else structure, help
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:00 AM
  4. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM
  5. Help with Structure
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 03:27 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
  •