Различен резултат
Защо при дефиниране на променливата points над while резултата е различен от този, когато тя е дефинира в while ? String name = scanner.nextLine(); String winnerName=""; int pointsWinner=0; int points=0; while (!name.equals("STOP")){ for(int i=0;i<name.length();i++){ points+=name.charAt(i);} if(points>pointsWinner){ pointsWinner=points; winnerName=name; } name=scanner.nextLine(); } System.out.printf("Winner is %s - %d!",winnerName,pointsWinner);
*************************************************************************************************************
String name = scanner.nextLine(); String winnerName=""; int pointsWinner=0; while (!name.equals("STOP")){ int points=0; for(int i=0;i<name.length();i++){ points+=name.charAt(i);} if(points>pointsWinner){ pointsWinner=points; winnerName=name; } name=scanner.nextLine(); } System.out.printf("Winner is %s - %d!",winnerName,pointsWinner);
Благодаря!