+ 3
So, I wrote a code which prints all possible combinations of a three lettered word. However, it displays the error message "erro
import java.io.*; public class Program { public static void main() { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); char a []=new char[3]; int i,j,c=0; char ch; String str; System.out.println("Enter a 3-lettered string"); str=in.readLine(); for(i=0;i<3;i++) { ch=str.charAt(i); a[c++]=ch; } for(i=0;i<3;i++) { for(j=0;j<3;j++) { System.out.print(a[i]); if(i==j) continue; else { System.out.print(a[j]); } } System.out.println(); } } }
3 Antworten
+ 5
readLine throws an exception so you need to handle Use a try {...existing code...} catch (Exception e) {}
Your main needs (String[] args)
Your print of a[i] needs to be moved to outer loop
+ 20
looks like some good amount of logical as well as syntax error
1)see main method
2)again look at the way u are making combination
for 3 letter words ... combinations possible will be 9 (if letters can repeat) & 6 (if letters can't repeat)
+ 1
Don't know if this will help too much, but try adding curly brackets to the if statement closer to the end of the code.