Skip to content

Instantly share code, notes, and snippets.

@mwangepatrick
Created July 31, 2022 12:38
Show Gist options
  • Save mwangepatrick/766ea5bde7772d08a3eb9a3d6e402ac4 to your computer and use it in GitHub Desktop.
Save mwangepatrick/766ea5bde7772d08a3eb9a3d6e402ac4 to your computer and use it in GitHub Desktop.
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.Scanner;
class HelloWorld {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in); // Reading from System.in
//Enter the number of items to input
System.out.println("Enter a number: ");
int n = reader.nextInt(); // Scans the next token of the input as an int.
int[] x = new int[n];
if(n<0) n=0; if(n>100)n=100;
//collect numbers up to the nth item
System.out.println("Enter: "+n+" Numbers \n");
for (int i = 0; i < n; i++) {
x[i]= reader.nextInt();
}
reader.close();
//start printing based on the values inputed.
for (int i = 0; i < n; i++) {
System.out.println(OnaDataHelperFunction(x[i]));
}
}
private static String OnaDataHelperFunction(int val){
if ((val%5)==0 && (val%3)==0)
return "OnaData";
else if((val%5)==0)
return "Data";
else if((val%3)==0)
return "Ona";
else
return "N/A";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment