Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GameOfWords {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String bestWord="";
- int bestPoints=0;
- System.out.println("Моля въведете дума, въведете'END OF GAME', за да прекратите играта:");
- while(true) {
- String entry = scanner.nextLine();
- if(entry.equalsIgnoreCase("end of game")) {
- break;
- } else {
- int entrysPoints = points(entry);
- if(entrysPoints>bestPoints) {
- bestWord = entry;
- bestPoints = entrysPoints;
- }
- }
- }
- System.out.println();
- System.out.println("Winner is word:"+bestWord);
- System.out.println("Points:"+bestPoints);
- }
- static int points(String word) {
- int score=0;
- char[] letters = word.toCharArray();
- if(Character.isUpperCase(letters[0])) {
- score+=15;
- }
- for(int i=0;i<letters.length;i++) {
- score+=letters[i];
- }
- if(letters[letters.length-1]=='t') {
- score+=20;
- }
- if(letters.length>=10) {
- score+=30;
- }
- return score;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement