I am using Scanner to read off a text file named\"Hello.txt\" , that contains th
ID: 3619310 • Letter: I
Question
I am using Scanner to read off a text file named"Hello.txt" , that contains the message "bobwright was yerbu yshdbfhshwjbyu".I want to make a program that checks if a persons scanner input eg"bob" can be found in the text file. If it is found a message "Yes"appears. If a persons scanner input cannot be found , 'No'appears.
import java.io.*;
import java.util.Scanner;
public class Exsize4
{
public static void main(String[] args)throwsIOException
{
File theText = newFile("Hello.txt");
Scanner in = newScanner(theText);
subString(in);
}
public static voidsubString(Scanner console)
{
Scannerinhere = new Scanner(System.in);
System.out.println("Type a letter you think is in the text. Is itthere?");
Stringword = inhere.next();
for(int i= 0 ; i< console.length() ; i++)
{
if((word.charAt(i).equals(console.charAt(i))
{
System.out.println("Yes");
}
}
}
Explanation / Answer
please rate - thanks import java.io.*; import java.util.Scanner; public class Exsize4 { public static void main(String[] args)throwsIOException { File theText = newFile("Hello.txt"); Scanner in = newScanner(theText); subString(in); } public static voidsubString(Scanner console) { Stringmessage; int i,j,k,m; Scanner inhere = new Scanner(System.in); message=console.nextLine(); System.out.println("Type a word you think is in the text. Is itthere?"); String word = inhere.next(); i=0; j=0; while(jRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.