Results 1 to 4 of 4

# Thread: Need some help plz

- 10-22-2008, 06:09 PM #1Member
- Join Date
- Oct 2008
- Posts
- 1

- Rep Power
- 0

## Need some help plz

Hello, i have written this for part of uni course work and i am struggling to get it to work, can one else see any major problem with my work that they could point out to me.

import java.util.scanner

public class Calculate

{

public static void main( String args[] )

{

Scanner input = new Scanner ( System.in):

int number1: // first number

int number2: // second number

int number3: // third number

int largest: // largest value

int smallest: // smallest value

int sum: // sum of numbers

int product: // product of numbers

int average: // average of numbers

System.out.print("Enter first integer:")://Prompt

number1 = input.nextInt(); //read first number from user

System.out.print("Enter second integer:");//Prompt

number2 = input.nextInt(); //read second number from user

System.out.print("Enter third interger:");//prompt

number3 = input.nextInt(); //read third number from user

largest = number1:

smallest = number1:

if (number1 > number2 > number3)

System.out.printf("Largest is %d > %d\n", number1 number2 number3);

if (number1 < number2 <number3)

system.out.printf("Smallest is %d < %d\n", number1 number2 number3);

sum - number1 + number2 + number3

System.out.printf( "Sum is %d\n", sum ); // display sum

if ((number1 + number2 + number3)/3)

System.out.printf( "Average is %d\n", sum );

if (number1*number2*number3)

}

}//end of Method

I would be thankfull for any feedback as i am very new to java having only been doing it for a a couple of weeks now.

The idea behind it is that it should help to find the largest of three numbers, then the smallest the product the average and the sum.

Thanks

- 10-22-2008, 06:15 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,372
- Blog Entries
- 1

- Rep Power
- 20

This is wrong,

Java Code:if (number1 > number2 > number3)

Can you tell me what's the logic you have to solve this problem. Take a seat and spend a lots of time to design your application first. If you have a strong design coding is not difficult at all.

- 10-22-2008, 06:18 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,372
- Blog Entries
- 1

- Rep Power
- 20

Oh my pal, there are lots of errors. How long you start to learn Java? You have misses lots of basis there in your code.

- 10-22-2008, 06:28 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,372
- Blog Entries
- 1

- Rep Power
- 20

Just check the following code. Compare it with your code above.

Java Code:import java.util.Scanner; public class Calculate { public static void main( String args[] ) { Scanner input = new Scanner ( System.in); int number1; // first number int number2; // second number int number3; // third number int largest; // largest value int smallest; // smallest value int sum; // sum of numbers int product; // product of numbers int average; // average of numbers System.out.print("Enter first integer:");//Prompt number1 = input.nextInt(); //read first number from user System.out.print("Enter second integer:");//Prompt number2 = input.nextInt(); //read second number from user System.out.print("Enter third interger:");//prompt number3 = input.nextInt(); //read third number from user // Make the number1 as maximum largest = number1; if(largest < number2) largest = number2; if(largest < number3) largest = number3; System.out.println("Maximum is: " + largest); // Make the number1 as minimum smallest = number1; if(smallest > number2) smallest = number2; if(smallest > number3) smallest = number3; System.out.println("Smallest is: " + smallest); } // End of method } // End of class

## Bookmarks