(Solved) : Question States String Methods Write Java Program Figure String Includes Dollar Sign Use Q42743114 . . .

The question states:

String Methods: Write a Java program to figure out if a stringincludes a dollar sign “$”. (use
keyboard to enter a string)’

This is my current code. I am not sure what is wrong with it. Nomatter what I input as my string, it says that it does include the$ sign.

import java.util.Scanner;

public class StringMethods {

   public static void main(String[] args) {

       Scanner sc=newScanner(System.in);
       System.out.println (“String Search$”);
       System.out.println(“Please enter astring: “);
       String str_input=sc.nextLine(); //input a string

       Stringstr_output=formatParagraph(str_input);
      System.out.println(str_output);  
   }

   public static String formatParagraph(String str){
       String temp=””;
      
       if(temp.indexOf(“$”)!=-1)
       {
       System.out.println(“String: This isan Example that does NOT include $”);
       }
       else
       {
       System.out.println(“String: This isan Example that does include $”);
       }
       return temp;
   }
}

Expert Answer


Answer to The question states: String Methods: Write a Java program to figure out if a string includes a dollar sign “$”. (use…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us