Answer to Question #296296 in Java | JSP | JSF for Lener

Question #296296

Write a program to take a String as input then display the position of a particular character given as input using indexOf() function of String class. Don't use charAt() function.

Enter a String

JapanIsSupremE

Enter character to find: e

Index Position: 11


1
Expert's answer
2022-02-10T13:32:10-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a String");
        String line = in.nextLine();
        System.out.print("Enter character to find: ");
        String toFind = in.nextLine();
        System.out.println("Index Position: " + line.indexOf(toFind.toCharArray()[0]));
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS