0

Good evening im seeking help with this program, it is in a loop that ends if a negative number is entered, I am trying to get the largest number entered in the do while loop, ive tried creating a temporal variable (temp), but I dont know where to go from there, Help please, And to make it more FUN I cant use ARRAYS!!... but still pleeeeeeeese HELP!

do{
    System.out.println(" Enter a number ");
      ingreso = leer.nextInt();
          i++;

          //EFFORTS TO TRY TO GET THE LARGEST NUM:
          sum = sum + ingreso;
          temp = ingreso;
          
          if(may > temp){
               System.out.println("The largest number is:  " + may);
              }

    }
         while(ingreso >= 0);
          average = sum/i;

     System.out.println("Numbers entered " + i);
     System.out.println("Average: " + average);
}

Edited by rayden150: How to find the largest number in this Iteration?

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by Taywin
0

If you want to find a largest number which is always a positive number, declare a variable outside the do-while loop and initial it with any value below 0. Then right after each input from a user, compare the value with the variable of largest number you have. If the newly input value is greater than the value in the variable, assign the value to the variable. After you are done with the while loop, you should have the largest number.

This topic has been dead for over six months. 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.