I am at my wits end with this code.
I've been working on it for at least 2 weeks and the same error appears.
The error, itself, is the incompatible types error. It appears underneath the division symbol.

// DivideByFive.java - This program determines if a number is divisible by 5 and prints
// the result or the fact that the number is not divisible by five.
// Input:  Interactive.
// Output:  Result of division or message.

import javax.swing.*;

public class DivideByFive
	public static void main(String args[])
		int number;
		String numberString;

		numberString = JOptionPane.showInputDialog("Enter an integer: ");
		number = Integer.parseInt(numberString);

		// Test number here. If divisible by 5, call divideByFive(), else print message.
		if (number / 5)
			System.out.println("Sorry, " + number + " is not divisible by 5 ");

	} // End of main() method.

	// Write divideByFive() method here.
	 public static void divideByFive(int number)
		System.out.println(number + " is divisible by 5 ");

} // End of DivideByFive class.
7 Years
Discussion Span
Last Post by kashokreddy14

You are making two mistakes here by the look of it. The first is the type of result you want and the second is the function used.

The if statement requires a Boolean value in the brackets to control execution. Your entry results in a numeric value, the number divided by five. What you need to do is compare this result with something to attain a boolean result.

You could see if the result is equal to '0' but this does not determine if it is divisible by 5. You will need a different function here for the program to work. (Check out modular division %)


EDIT: Little late for reply but anyway...

You tried to apply your logic to the problem but chosen wrong approach. Operation inside the brackets it is a statement of a condition. If the condition is fulfilled then what ever is inside brackets is executed. By providing mathematical operation as you did, which seems to be logical to you, you cannot solve this. What you are looking for is and condition when numbers' division by five will return number without decimal part. For this you need to use reminder operation represented by %. So if you do 7&5 return is 2, if you do 15%5 return is 0 (zero). You need to covert mathematical operation to condition so you need to use "==" ">" "<" ">=" "<=" in this case

if(number % 5 == 0)

Edited by peter_budo: n/a


Thank you two SO much! I had it that way at first, but I closed the 5 off with a closing parenthesis.
Again, thank you very much!

Edited by Jay V.: n/a


import java.sql.*;
public class DisplayRecords{
public static void main(String ar[]) throws Exception{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "system");
Statement stmt=con.createStatement();
String query="select * from emp";
System.out.println("executing the query:"+query);
ResultSet rs=stmt.executeQuery(query);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.