-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram7.java
More file actions
28 lines (22 loc) · 982 Bytes
/
Program7.java
File metadata and controls
28 lines (22 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Day 2 - Week 1
//Input: The input is an integer 'n' which denotes the given number
// Output: If the given number is trendy number. then print 'Trendy Number'. Otherwise print "Not Trendy Number". if the given number is not a 3 digit number. then print "Invalid number".
// Instruction: A number is said to be a trendy number if it has 3 digits and the middle digit is divisible by 3
import java.util.Scanner;
public class Program7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a three-digit number:");
int num = sc.nextInt();
if (num < 100 || num > 999) {
System.out.println("Invalid number");
} else {
int middleDigit = (num / 10) % 10;
if (middleDigit % 3 == 0) {
System.out.println("Trendy Number");
} else {
System.out.println("Not Trendy Number");
}
}
}
}