Answer:
import java.util.Scanner;
public class PrintNumberToWordie {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a number");
int num = in.nextInt();
if(num == 1){
System.out.println("ONE");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 2){
System.out.println("TWO");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 3){
System.out.println("THREE");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 4){
System.out.println("FOUR");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 5){
System.out.println("FIVE");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 6){
System.out.println("SIX");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 7){
System.out.println("SEVEN");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 8){
System.out.println("EIGHT");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 9){
System.out.println("NINE");
if(num%2==0)
System.out.println("Divisible by 2");
}
else if (num == 10){
System.out.println("TEN");
if(num%2==0)
System.out.println("Divisible by 2");
}
else{
System.out.println("No Match");
}
}
}
Step-by-step explanation:
- Using Java programming language
- Import Scanner class
- Prompt user to enter a number, receive and store in a variable
- Use if and else if statements to check the value of the number and output the corresponding spelling
- Use and inner if statement to check divisibility by two using the modulo operator