How to print out executable code in Java, without executing it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to print out executable code in Java, without executing it?

I want to create a library in Java, so whenever I need to refresh my memory on a certain topic, I can access it immediately just by inputting a certain number. However, once I put the pieces of code into System.out.println(), it takes it as a part of the code and starts spitting out errors. I just need a way to block the execution of a particular part of a code, while still being able to print it. How do I do this? Code: import java.util.Scanner; class MyClass { public static void main(String[ ] args) { int onedotone = 1; Scanner userinput = new Scanner(System.in); int input = 0; input = userinput.nextInt(); if (input == 1) { System.out.println("Overview"); } if (input == 1.1) { System.out.println(class MyClass { //Here is the problem public static void main(String[ ] args) { System.out.println("Hello World"); } } ); } else { System.out.println("Not Found"); } } }

29th Aug 2019, 12:00 PM
Artem
1 Answer
0
I would perhaps use files (at least in Python) to read from. you could also do links to a blog you’ll write and can’t you use a lot of \ escapes? no expert btw
29th Aug 2019, 12:27 PM
Brave Tea
Brave Tea - avatar