for my second input I'm trying to use an if statement to print location of the first "a" but if there isn't an "a" than print there is no a. I keep getting error int cannot be converted to boolean on line (a = noSpace.indexOf("a");) tried to debug but I'm not sure how to fix, first time I've received this error. I've marked line with error >>>
public class ManyStrings
{
public static void main(String[] args)
{
//first input
String title="";
Scanner input = new Scanner(System.in);
System.out.print("Enter a statement: ");
title = input.nextLine();
int x = title.indexOf(" ");
System.out.println("The length of the string is "+ title.length()+".");
System.out.println("The first word is " +"\""+ title.substring(0,x)+"\"");
System.out.println(title.toUpperCase());
//second input
System.out.print("Enter second statement: ");
String strg2 = input.nextLine();
String noSpace = strg2.replaceAll("\\s","");
System.out.println(noSpace.toLowerCase());
noSpace = noSpace.replaceAll("n","r");
System.out.println(noSpace);
boolean a;
>>> a = noSpace.indexOf("a");
if(a=-1) {
system.out.print("There are no a's in the String.");
}else {
System.out.print("location of first a: "+ a);
}
}
}
Aucun commentaire:
Enregistrer un commentaire