0% found this document useful (0 votes)
3 views6 pages

Java Conditional Thinking 50 Programs

The document contains 50 Java programs that demonstrate various conditional statements and logic. Each program addresses a specific problem, such as determining if a number is positive, negative, or zero, checking for leap years, and validating dates. The examples cover a wide range of topics, including arithmetic operations, character checks, and geometric properties.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Java Conditional Thinking 50 Programs

The document contains 50 Java programs that demonstrate various conditional statements and logic. Each program addresses a specific problem, such as determining if a number is positive, negative, or zero, checking for leap years, and validating dates. The examples cover a wide range of topics, including arithmetic operations, character checks, and geometric properties.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Conditional Thinking - 50 Programs

1. Positive, Negative, or Zero


import [Link].*;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner([Link]);
int n=[Link]();
if(n>0) [Link]("Positive");
else if(n<0) [Link]("Negative");
else [Link]("Zero");
}
}

2. Even or Odd
import [Link].*;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner([Link]);
int n=[Link]();
if(n%2==0) [Link]("Even");
else [Link]("Odd");
}
}

3. Divisible by 5
if(n%5==0) [Link]("Divisible");
else [Link]("Not Divisible");

4. Divisible by 3 and 5
if(n%3==0 && n%5==0) [Link]("Yes");
else [Link]("No");

5. Leap Year
if((year%400==0)|| (year%4==0 && year%100!=0))
[Link]("Leap Year");
else
[Link]("Not Leap Year");

6. Larger of Two Numbers


if(a>b) [Link](a);
else [Link](b);

7. Largest of Three Numbers


if(a>b && a>c) [Link](a);
else if(b>c) [Link](b);
else [Link](c);

8. Temperature Category
if(t<20) [Link]("Cold");
else if(t<=30) [Link]("Warm");
else [Link]("Hot");

9. Vowel or Consonant
char ch='a';
if("aeiouAEIOU".indexOf(ch)!=-1)
[Link]("Vowel");
else
[Link]("Consonant");

10. Character Type


if([Link](ch)) [Link]("Uppercase");
else if([Link](ch)) [Link]("Lowercase");
else if([Link](ch)) [Link]("Digit");
else [Link]("Special Character");

11. Valid Triangle


if(a+b>c && a+c>b && b+c>a)
[Link]("Valid");
else
[Link]("Invalid");

12. Triangle Type


if(a==b && b==c) [Link]("Equilateral");
else if(a==b || b==c || a==c) [Link]("Isosceles");
else [Link]("Scalene");

13. Grade System


if(m>=90) [Link]("A");
else if(m>=75) [Link]("B");
else if(m>=50) [Link]("C");
else if(m>=35) [Link]("D");
else [Link]("F");

14. Multiple of Another


if(a%b==0 || b%a==0) [Link]("Yes");
else [Link]("No");

15. Greeting by Hour


if(h>=5 && h<12) [Link]("Good Morning");
else if(h<17) [Link]("Good Afternoon");
else if(h<21) [Link]("Good Evening");
else [Link]("Good Night");

16. Voting Eligibility


if(age>=18) [Link]("Eligible");
else [Link]("Not Eligible");

17. Even/Odd Pair


if(a%2==0 && b%2==0) [Link]("Both Even");
else if(a%2!=0 && b%2!=0) [Link]("Both Odd");
else [Link]("One Even One Odd");

18. Alphabet Range


if(ch>='a' && ch<='m') [Link]("a-m");
else if(ch>='n' && ch<='z') [Link]("n-z");

19. Day Name


switch(day){
case 1:[Link]("Monday");break;
case 2:[Link]("Tuesday");break;
default:[Link]("Invalid");
}

20. Days in Month


if(month==2) [Link](28);
else if(month==4||month==6||month==9||month==11)
[Link](30);
else [Link](31);

21. Distinct Digits


int a=n/100,b=(n/10)%10,c=n%10;
if(a!=b && b!=c && a!=c) [Link]("Distinct");
else [Link]("Not Distinct");

22. Middle Digit Check


int a=n/100,b=(n/10)%10,c=n%10;
if(b>a && b>c) [Link]("Largest");
else if(b<a && b<c) [Link]("Smallest");
else [Link]("Neither");

23. First and Last Digit Equal


int first=n/1000,last=n%10;
if(first==last) [Link]("Equal");
else [Link]("Not Equal");

24. Single/Double/Multi Digit


if(n>=-9 && n<=9) [Link]("Single");
else if(n>=-99 && n<=99) [Link]("Double");
else [Link]("Multi");

25. Multiple of 7 or Ends with 7


if(n%7==0 || n%10==7) [Link]("Yes");
else [Link]("No");

26. Quadrant
if(x>0 && y>0) [Link]("Q1");
else if(x<0 && y>0) [Link]("Q2");
else if(x<0 && y<0) [Link]("Q3");
else [Link]("Q4");

27. Currency Notes


if(amount%100==0) [Link]("Possible");
else [Link]("Not Possible");

28. Range [100,999]


if(n>=100 && n<=999) [Link]("Inside");
else [Link]("Outside");

29. Third Angle


int third=180-(a+b);
[Link](third);
30. Perfect Square
boolean flag=false;
for(int i=1;i*i<=n;i++){
if(i*i==n){ flag=true; break; }
}
[Link](flag?"Perfect Square":"Not Perfect Square");

31. Letter, Digit, or Neither


if([Link](ch)) [Link]("Letter");
else if([Link](ch)) [Link]("Digit");
else [Link]("Neither");

32. FizzBuzz
if(n%3==0 && n%5==0) [Link]("FizzBuzz");
else if(n%3==0) [Link]("Fizz");
else if(n%5==0) [Link]("Buzz");

33. Median of Three Numbers


int[] arr={a,b,c};
[Link](arr);
[Link](arr[1]);

34. AM or PM
if(hour<12) [Link]("AM");
else [Link]("PM");

35. Tax Eligibility


if(age>18 && income>500000)
[Link]("Eligible");
else
[Link]("Not Eligible");

36. Positive and Sum < 100


if(a>0 && b>0 && a+b<100)
[Link]("Yes");
else
[Link]("No");

37. Number to Word


String[] words={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
[Link](words[n]);

38. Weekday or Weekend


if(day>=1 && day<=5) [Link]("Weekday");
else if(day==6 || day==7) [Link]("Weekend");

39. Electricity Bill


if(units<=100) bill=units*1.5;
else if(units<=200) bill=100*1.5+(units-100)*2;
else bill=100*1.5+100*2+(units-200)*3;
40. Password Validation
if([Link]()>=8 && [Link](".*\\d.*"))
[Link]("Valid");
else
[Link]("Invalid");

41. Point on Axis


if(x==0 && y==0) [Link]("Origin");
else if(y==0) [Link]("X-axis");
else if(x==0) [Link]("Y-axis");

42. Pythagorean Triplet


if(a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)
[Link]("Yes");
else
[Link]("No");

43. Valid Date


if(month>=1 && month<=12 && day>=1 && day<=31)
[Link]("Valid");
else
[Link]("Invalid");

44. Clock Angle


double angle=[Link]((30*h+0.5*m)-(6*m));
angle=[Link](angle,360-angle);
[Link](angle);

45. Arithmetic Progression


if(b-a==c-b) [Link]("AP");
else [Link]("Not AP");

46. Geometric Progression


if(b*b==a*c) [Link]("GP");
else [Link]("Not GP");

47. Digit Sum Logic


int a=n/100,b=(n/10)%10,c=n%10;
if(a+c==b) [Link]("Yes");
else [Link]("No");

48. Sum of Digits > Product


int sum=0,prod=1,temp=n;
while(temp>0){
int d=temp%10;
sum+=d;
prod*=d;
temp/=10;
}
if(sum>prod) [Link]("Yes");

49. Compare Dates


if(m1<m2 || (m1==m2 && d1<d2))
[Link]("First Date Earlier");
else
[Link]("Second Date Earlier");

50. Century from Year


int century=(year+99)/100;
[Link](century+"th century");

You might also like