I have to replace a certain character(chosen by the user) in a given string, with another character(inputted by user). E.g:
"enter a string:" Good Morning
"inputted by user:" o
"change to:" z
"final output:" Gzzd Mzrning
The problem is that Im not allowed to use loops or the replace method, only basic java stuff...This is my code so far(although it doesnt compile)
import java.util.Scanner;
public class Recur
{
public static void main (String[] args)
{
Scanner input=new Scanner(System.in);
String word= input.nextLine();
int spaces=word.length();
String [] letter= new String [spaces];
String swop=input.nextLine();
String substitute=input.nextLine();
System.out.println(word);
System.out.println(swop);
System.out.println(substitute);
int a=0,b=0;
if(a<letter.length)
{
if(letter[a]==swop) {
letter[a]=substitute;
b=1; }
a++; }
if(b==1)
{ String revised = new String(letter);
System.out.println(revised); }
if(b==0)
{ System.out.println(""); }
}
}
Any help will be greatly appreciated as i need to finish this tonight. thnx

New Topic/Question
Reply




MultiQuote







|