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.

Recommended Answers

All 5 Replies

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)

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!

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);

any body can plz help me resolving the error occured in the program

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.