Question
public class ScrabbleScore { public static void main(String[] args) { //Declaring variables String str; int score; //Scanner object is used to get the inputs entered
public class ScrabbleScore { public static void main(String[] args) {
//Declaring variables String str; int score; //Scanner object is used to get the inputs entered by the user Scanner sc=new Scanner(System.in); //This loop continues to execute until the user enters a valid string while(true) { //getting the string entered by the user System.out.println("Enter the Strng :"); str=sc.nextLine(); /* calling the method by passing * the user entered string as argument */ score=calculateScore(str); //If the returned value of the method is -1 then display error message if(score==-1) { System.out.println("** Invalid String **"); continue; } else { //Displaying the Score of the string System.out.println("Score :"+score); break; } } }
/* This method will calculate the score for the String * @ params word of type String * @return score of type integer */ public static int calculateScore(String word) { int score=0; for(int i=0;i }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started