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

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.

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.