you maybe want to write "System.out.println(x);" with parametric x values..public static void main(String[] args){int x;String str;for (x=0; x<5; x++) {str = "System.out.println("+x+");";System.out.println(str);}}