This IntelliJ java file names Create a String array which stores these example f
ID: 3783616 • Letter: T
Question
This IntelliJ java
file names Create a String array which stores these example filenames: "random.py", "assignment.doc", "report.pdf", "math.c", "airfares.xls", "main.java", "computing.java".
And, create a String array which contains ".java", ".c", and ".py" which are all file extensions for program code files.
Write a loop which examines the first array and uses the second array to print all the files which seem to contain program code.
Modify the first array by adding some extra filenames to the array. Does your program still work?
Explanation / Answer
public class subString {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] fileNames = {"random.py", "assignment.doc", "report.pdf", "math.c", "airfares.xls", "main.java", "computing.java"};
String[] extensions = {".java", ".c",".py"};
//int hat;
for(int i=0;i<fileNames.length;i++)
{
for(int j=0;j<extensions.length;j++)
{
if(fileNames[i].indexOf(extensions[j])>0)
{
System.out.println(fileNames[i]);
break;
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.