prompts the user for a sentence and a string using Scanner - Java File Path IO

Java examples for File Path IO:Scanner

Description

prompts the user for a sentence and a string using Scanner

Demo Code


import java.util.Scanner;

public class RemoveString {


  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    /*from  w w  w.  jav a2 s .  c  om*/
    String sentence;
    String text;
    
    System.out.print("Enter a sentence:");
    sentence=scan.nextLine();
    
    System.out.print("Enter a string:");
    text=scan.nextLine();
    
    System.out.print(sentence.replace(text, ""));
    scan.close();
  }

}

Related Tutorials