Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Why won\'t my program compile ??? please help fix anything that needs to be fixe

ID: 3886192 • Letter: W

Question

Why won't my program compile ??? please help fix anything that needs to be fixed

/**
* Assignment 2.
*   
* @version 2.0
*/

import java.util.*;
public class Assignment2
{
public static void main(String[] args)
{
Scanner Mescan = new Scanner(System.in);
  
int yes = 1;
int no = 0;

int String1 = String1;
int String2 = String2;

  
  

if (yes == 1){
System.out.println();
}
else if (no == 0){
System.out.println();

}
  
System.out.println("Do you want to consider capitalization? Type 1 for YES, 0 for NO");
if (yes == 1){
System.out.println();
}
else if (no == 0){
System.out.println();
}
  
int int1 = Integer.parseInt("spaces");
int int2 = Integer.parseInt("caps");
  
  
if (String1.contains(String2))
{
if (String1.startsWith(String2))
{
System.out.println("Your search is in the beginning of the input.");
}
else if (!String1.startsWith(String2))
System.out.println("Search term starts at index" + String1.indexOf(String2) + "and ends at index" + (String1.indexOf(String2) + String2.length() - 1));
if (String.endWith(String2))
{

System.out.println("Your search is at the end of the input");
}
else if (!String1.endsWith(String2))
System.out.println("Search term starts at index" + String1.indexOf(String2) + "and ends at index" + (String1.indexOf(String2) + String2.length() - 1));
  
}
}
}

Explanation / Answer

/** * The program was not being compiled because you are trying to assign * string to integer * I have commented couple of lines you can check and compare them */ import java.util.*; public class Assignment2 { public static void main( String[] args ) { Scanner Mescan = new Scanner(System.in); int yes = 1; int no = 0; /*int String1 = String1; int String2 = String2;*/ String String1 = Mescan.nextLine(); String String2 = Mescan.nextLine(); if( yes == 1 ) { System.out.println(); } else if( no == 0 ) { System.out.println(); } System.out.println("Do you want to consider capitalization? Type 1 for YES, 0 for NO"); if( yes == 1 ) { System.out.println(); } else if( no == 0 ) { System.out.println(); } int int1 = Integer.parseInt("spaces"); int int2 = Integer.parseInt("caps"); if( String1.contains(String2) ) { if( String1.startsWith(String2) ) { System.out.println("Your search is in the beginning of the input."); } else if( !String1.startsWith(String2) ) System.out.println("Search term starts at index" + String1.indexOf(String2) + "and ends at index" + ( String1.indexOf(String2) + String2.length() - 1)); if( String1.endsWith(String2) ) { System.out.println("Your search is at the end of the input"); } else if( !String1.endsWith(String2) ) System.out.println("Search term starts at index" + String1.indexOf(String2) + "and ends at index" + ( String1.indexOf(String2) + String2.length() - 1)); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote