Results 1 to 6 of 6
Thread: What's going on with my code?
- 10-16-2012, 09:49 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 24
- Rep Power
- 0
What's going on with my code?
Hi! Sorry to bother everyone again, I was hoping someone can correct the error I am getting with my java code? I really want to do well in my college module but find java programming tough. The programme is trying to find the highest number in a four-digit number. However, I keep getting a compilation error " error: bad operand types for binary operator '&&' if (Digit1 > Digit2 && Digit3 && Digit4) first type:boolean second type:int
Java Code:
import java.util.Scanner;
public class Digit
{
public static void main(String[]args)
{
int Num;
Scanner in = new Scanner(System.in);
System.out.print("Enter a four digit number: ");
Num = Integer.parseInt(in.nextLine());
int Digit1 = (Num / 1000);
int Digit2 = ((Num % 1000) / 100);
int Digit3 = (((Num % 1000) % 100) / 10);
int Digit4 = ((((Num % 1000) % 100) % 10) / 1);
if (Digit1 > Digit2 && Digit3 && Digit4)
{
System.out.print((Digit1) + " is greater than " + (Digit2) + " and " + (Digit3) + " and " + (Digit4) + ".");
}
else if (Digit2 > Digit1 && Digit3 && Digit4)
{
System.out.print((Digit2) + " is greater than " + (Digit1) + " and " + (Digit3) + " and " + (Digit4) + ".");
}
else if (Digit3 > Digit1 && Digit2 && Digit4)
{
System.out.print((Digit3) + " is greater than " + (Digit1) + " and " + (Digit2) + " and " + (Digit4) + ".");
}
else if (Digit4 > Digit1 && Digit2 && Digit3)
{
System.out.print((Digit4) + " is greater than " + (Digit1)+ " and " + (Digit2) + " and " + (Digit3) + ".");
}
}
}
- 10-16-2012, 10:39 PM #2
Member
- Join Date
- Jan 2012
- Posts
- 49
- Rep Power
- 0
Re: What's going on with my code?
I cant read this when you don't follow forum rules.
- 10-16-2012, 10:47 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Re: What's going on with my code?
if (Digit1 > Digit2 && Digit3 && Digit4) {
doesn't work at all!
You have to do:
if (Digit1 > Digit2 && Digit1 > Digit3 && Digit1 > Digit4){
- 10-17-2012, 12:42 AM #4
Member
- Join Date
- Oct 2012
- Posts
- 24
- Rep Power
- 0
- 10-17-2012, 12:42 AM #5
Member
- Join Date
- Oct 2012
- Posts
- 24
- Rep Power
- 0
Re: What's going on with my code?
Thank you :)
- 10-17-2012, 09:43 AM #6
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
this code is not working I Dont know why ? Public void close the last code!!
By lukote04 in forum New To JavaReplies: 1Last Post: 03-25-2012, 02:40 AM -
I want the source code of DUK's Bank , the example code in Java EE 5 Tutorial 2010
By zahra in forum New To JavaReplies: 16Last Post: 01-31-2012, 08:36 PM -
My code was not executed properly.It will jumping to exception handling.my code is
By vinay4051 in forum EclipseReplies: 3Last Post: 08-10-2011, 09:17 AM -
servlet include method copying sorce code and executing source code as output how to
By shamkuma2k in forum Advanced JavaReplies: 0Last Post: 08-07-2011, 08:32 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks