Computer Science, asked by jhaayush580, 8 months ago

write a program to enter three numbers and a character. Find and display sum of the numbers if the given character is 's' and product of the numbers if the given character is 'p'.The program displays a message "Invalid Character "if the user enters a letter other than 's' or 'p'​

Answers

Answered by sharanya200636
3

Answer:

Answered

Explanation:

import java.io.*;

class GFG {

// Function to find string score

static int strScore(String str[], String s, int n)

{

int score = 0, index=0;

for (int i = 0; i < n; i++) {

if (str[i] == s) {

for (int j = 0; j < s.length(); j++)

score += s.charAt(j) - 'a' + 1;

index = i + 1;

break;

}

}

score = score * index;

return score;

}

// Driver code

public static void main (String[] args) {

String str[] = { "sahil", "shashanak"

, "sanjit", "abhinav", "mohit" };

String s = "abhinav";

int n = str.length;

int score = strScore(str, s, n);

System.out.println( score);

}

}

PLS MARK AS BRAINLIEST

Answered by arnavsrivastava639
0

Answer:

link 1:https://media.tenor.com/images/95cf96959ad9c218b5ce1fb1e8f2f032/tenor.gif

link 2:https://media.tenor.com/images/4d9a854c5a8f90fe5672b268a37e96ee/tenor.gif

Similar questions