+ 2
Can anybody tell me what's wrong in this code, it is creating problems with input with spaces. E. Vegetable pizza.
import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str=sc.nextLine(); String nstr=str.toLowerCase(); String a="abcdefghijklmnopqrstuvwxyz"; for(int i=0;i<=10;i++) { int c=0; for(int j=0;j<26;j++){ c++; if(nstr.charAt(i)==' '){ System.out.print(" "); c=c-1; } else if(nstr.charAt(i)==a.charAt(j)){ break; } }//closing of j System.out.print(a.charAt(26-c)); } } }
6 Réponses
+ 2
https://code.sololearn.com/cNk92Od5tmZC/?ref=app,
Thanks brother for your kind help.
0
Check by taking input vegetable pizza
0
I replaced (i<=10)with ( l-1),where l=length of inputting string. Then also amen problem occurs. Here's the new one.
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
String nstr=str.toLowerCase();
int l=nstr.length();
String a="abcdefghijklmnopqrstuvwxyz";
for(int i=0;i<=(l-1);i++)
{
int c=0;
for(int j=0;j<26;j++){
c++;
if(nstr.charAt(i)==' '){
System.out.print(" ");
c=c-1;
}
else if(nstr.charAt(i)==a.charAt(j)){
break;
}
}//closing of j
System.out.print(a.charAt(26-c));
}
}
}
0
Rithea Sreng,but i removed it then why the same error is occurring.
0
The outcome of vegetable pizza should be 'evtvgzyov kraaz'.
0
I didn't understand what you are trying to say.