How to find error of this program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to find error of this program

public class Main{ public static void main (String[] args) { //find the length String name="sam"; String name2="ram"; System.out.println(name.length()); //find the position element System.out.println(name.charAt(0)); //concatenate the string String name3=name+" and "+name2; System.out.println(name3); //replace the letter String name4=name.replace(oldchar:'a',newchar:'1'); System.out.println(name4); } }

18th Aug 2022, 2:46 PM
VH PROGRAMMER
VH PROGRAMMER - avatar
1 Answer
+ 2
By compiling!!!!!!!!!!!! No need to specify oldchar, newchar like that.. just write like : name.replace('a', '1') ;
18th Aug 2022, 2:49 PM
Jayakrishna 🇮🇳