public class findcharinstring {
public static void main(String[] args) {
int x = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the string:");
String string = sc.nextLine();
System.out.println("Enter the character to find:");
char f = sc.next().charAt(0);
int a = string.length();
char arr[] = new char[a];
for (int i = 0; i < a; i++) {
arr[i] = string.charAt(i);
if (arr[i] == f) {
System.out.println("character " + f + " is found at " + i);
x = 1;
}
}
if (x == 0) {
System.out.println("Character not found");
}
package com.dain.logics;
import java.util.Scanner;
public class findcharinstring { public static void main(String[] args) { int x = 1; Scanner sc = new Scanner(System.in); System.out.println("Enter the string:"); String string = sc.nextLine(); System.out.println("Enter the character to find:"); char f = sc.next().charAt(0); int a = string.length(); char arr[] = new char[a]; for (int i = 0; i < a; i++) { arr[i] = string.charAt(i); if (arr[i] == f) { System.out.println("character " + f + " is found at " + i); x = 1; } } if (x == 0) { System.out.println("Character not found"); }
}