java - loop error - fixing the loop means breaking something else and visa versa -


i new java, , i've been struggling loop assignment. can make program work intended, however, @ cost of having text @ end if user enters no values. if make code user enters no values doesn't have text (i.e. max number 0 , count max number 0), loop doesn't work. code included below. going on?

//name: //date: //file: //description: program allows user enter numbers , determine maximum value count how many times maximum value entered.  import java.util.scanner;  public class lab4b_hmcka {     public static void main (string [] args)     {     //variables     int num1, num2, max1 = 0, max2 = 0, count = 0, maxcount = 0;      system.out.println("          find maximum number");     system.out.println();      system.out.print("enter integer <0 ends input>: ");     scanner input = new scanner(system.in);     num1 = input.nextint();      if (num1 ==0)     {         system.out.println("no numbers entered except 0");     }      while (num1 != 0)     {         if (maxcount == 0)         {             system.out.print("enter integer <0 ends input>: ");             num2 = input.nextint();             max1 = math.max(num1, num2);             maxcount = maxcount + 1;             count = count + 1;             system.out.print("enter integer <0 ends input>: ");             num1 = input.nextint();             continue;         }         else         {             max2 = math.max(num1, max1);              if (num1 == max1)             {                 maxcount = maxcount + 1;                 count = count + 1;             }             else             {                 count = count + 1;             }             system.out.print("enter integer <0 ends input>: ");             num1 = input.nextint();         }       }          if (count == 1)             {             system.out.println("the maximum number " + max1);             }         else             {             system.out.println("the maximum numberis " + max2);             }         system.out.println("the count max number " + maxcount);     }  } 

i'm not entirely sure want achieve , tried achieve (whatever is), assume want terminate program if user wants quit right away (= enters 0 first). add return:

if (num1 == 0) {     system.out.println("no numbers entered except 0");     return; // terminate now. } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -