Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

take input and match the corresponding file

Tags:

java

file

input

I have 100 files named "1.exe","2.exe","3.exe",...,"100.exe" I want to take input from user as 1,2,3,... or 100 and run the corresponding exe file. For example if user inputs 45 , I will run file "45.exe" I don't want to use ifs or switches. Can anyone please help me.

like image 940
Arghya Chakraborty Avatar asked Nov 30 '22 23:11

Arghya Chakraborty


2 Answers

If the input is always equal to the filename of your exes you can do it with:

if( isInputNumberBetween1And100() )
    Runtime.getRuntime().exec( input + ".exe" );
like image 175
halex Avatar answered Dec 04 '22 04:12

halex


Runtime.getRuntime().exec( input + ".exe" ).waitFor();

will work if you want to to wait for it.

like image 41
Site Helpers Avatar answered Dec 04 '22 06:12

Site Helpers