Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Not getting the correct output

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Location
    Mumbai
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Not getting the correct output

    this is the program which gives output as " number is divisible by 5 and 6" or it will give "number is divisible by 5(6)" or "not divisible by either 5 and 6".
    the problem is when i entered 5 it gave "Number is divisible by 6" and when i enter 30 it gave "Number is not divisible either by 5 and 6"
    Kindly tell me what is wrong in it? I want to write this code by using if statements only.




    import javax.swing.JOptionPane;
    public class Divisibility {
     
     
    	public static void main(String[] args) {
    		String number=JOptionPane.showInputDialog(null, "Enter any number");
    		int no=Integer.parseInt(number);
     
    		if(no/5==0&&no/6==0)
    		{
    			JOptionPane.showMessageDialog(null, "The number is divisible by both 5 and 6");
    		}
    		else if(no/5==0^no/6==0)
    		{
    			if(no/5==0)
    				JOptionPane.showMessageDialog(null, "The number is divisible by 5");
    			else
    				JOptionPane.showMessageDialog(null, "The number is divisible by 6");
    		}
    		else
    			JOptionPane.showMessageDialog(null, "The number is not divisible by either 5 or 6");
    	}
     
    }
    Last edited by pbrockway2; December 26th, 2012 at 03:54 AM. Reason: code tags added


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Not getting the correct output

    Hi Ashish S, welcome to the forums!

    When you post code use the "code" tags. The idea is that you put [code] at the start of the code and [/code] at the end and that way the code will be correctly formatted when it appears on a web page.

    [Edit]

    Do you mean / or %?

  3. The Following User Says Thank You to pbrockway2 For This Useful Post:

    Ashish S (December 26th, 2012)

Similar Threads

  1. Not getting the correct output
    By KNAYERS in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 23rd, 2012, 01:59 PM
  2. how could I output to a text area the output of a method
    By mia_tech in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 12th, 2012, 07:49 PM
  3. [SOLVED] No errors, but output not correct? Only one loop performed correctly! Help please :)
    By coffecupcake in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 21st, 2012, 11:18 AM
  4. [SOLVED] Code is correct, but incorrect output?
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 6th, 2011, 02:32 PM
  5. Correct Coupling
    By poulenc in forum Java Theory & Questions
    Replies: 0
    Last Post: December 26th, 2010, 04:28 AM