Hi, Im very new to java (about a month) with a useless lecturer who has taught us nothing. Everything I have learnt so far as been on my own at home trying things.
I did a question, but I wanted to try adding things to it to learn so started experimenting. Im sure it will look a mess to some here but like I said I have very limited knowledge and Im new. My problem is the final if statement seems to run no matter what the condition - its only supposed to show how many negative numbers were entered if the previous if statment is triggered and asks the user if they want to see this (and this is only triggered if any negative number were entered in the program at all anyway, that bit seems to work).
public class QuestionTwo
{
public static void main(String[] args)
{
int Min=0, Min2, Max=0, Result=0, Check;
boolean Ask=false;
do
{
Check=0;
if(Min>Max)
{
System.out.println("Please make sure the Minimum number entered is smaller than the larger number entered");
System.out.println();
}
else
;
System.out.println("Enter a Minimum Number: ");
Min = SavitchIn.readLineInt();
while (Min<0)
{
if(Min<0)
{
System.out.println("Please make sure the Minimum Number entered is positive: ");
Min = SavitchIn.readLineInt();
Check=Check+1;
}
else
;
;
}
System.out.println("Enter a Maximum Number: ");
Max = SavitchIn.readLineInt();
while(Max<0)
{
if(Max<0)
{
System.out.println("Please make sure the Maximum Number entered is positive: ");
Max = SavitchIn.readLineInt();
Check=Check+1;
}
else
;
;
}
}
while(Min>Max);
Min2=Min;
for (Min=Min; Min<=Max; Min++)
{
Result=Result+Min;
}
System.out.println("\nThe sum of all numbers between "+Min2+" and "+Max+" = "+Result);
System.out.println();
if(Check>0)
{
System.out.println("Would you like to see how many negative numbers were incorrectly entered?\nt=Yes f=No\n");
Ask = SavitchIn.readLineBoolean();
}
else
;
if(Ask=true)
System.out.println(+Check+ " Negative number(s) were entered");
else
System.out.println("Goodbye");
}// main
} // QuestionTwo
The program should;
Ask for a minimum number, and use a loop to check of it is negative (count each negative number entered)
then
Ask for a maximum number, with the same conditions as the minimum.
It will then check if the minimum is larger than the maximum, and if it is start the do while loop again, this time with a warning.
It then counts the sum of all the numbers with a for loop and displays the answer.
Finally the final two if statements I have already described should run. Any one know how to fix this (Ive been trying for a while)?
Edit: Just realised you will need SavitchIn.class to run this, as its what we are using to learn. I found a link to it here http://www.cs.miami.edu/~duncan/spring03/csc220/classes/SavitchIn.class
Thanks, Michael