+ 4

What is the error? Can anyone please explain?

11th Feb 2017, 4:10 AM
Prabhakar Dev
Prabhakar Dev - avatar
2 odpowiedzi
+ 4
import java.io.*; public class Program { public static void main(String args[])throws IOException{BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); int x=1; int s; String[] p={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","@","#","
quot;,"%","&","-","+","*",":",";","!","?","=","^","×","÷"}; int l=Integer.parseInt(r.readLine()); if(l>=8&&l<=20){ for(x=1;x<=l;x++){ s=Math.round(Math.random()*52); System.out.print(p[s]); } } } }
11th Feb 2017, 4:10 AM
Prabhakar Dev
Prabhakar Dev - avatar
+ 1
The first thing I suggest doing is declaring s as a long instead of an int, then casting s to int inside the System.out.print() call. long s; ... after a few lines ... System.out.print(p[(int) s]); Other than that, I'm not sure what your code is supposed to do, exactly. Please elaborate.
11th Feb 2017, 4:33 AM
DaemonThread
DaemonThread - avatar