//WAP to enter a character and print it is vowel or consonant
public class Ex7_1
{
static void main(char ch)
{
if(ch=='a' ||ch=='e' ||ch=='i' ||ch=='o' ||ch=='u')
System.out.println("Vowel");
else
System.out.println("Consonent");
}
}
Write a program to input a number and find out if it is single digit or a double digit
number. Display the output with proper messages
public class Ex7_2
{
static void main(int n)
{
if(n>0 && n<10)
System.out.println("Single Digit");
else if(n>9 && n<100)
System.out.println("Double Digit");
}
//WAP to input a character and check whether it is a capital letter or a small letter
public class Ex7_3
{
static void main(char ch)
{
if(ch>=65 && ch<=90)
System.out.println("Capital letter");
else
System.out.println("Small Case");
}
}
//WAP to accept three numbers from the user and print which is the largest number
public class Ex7_2_1
{
static void main(int n1, int n2, int n3)
{
if(n1>n2 && n1>n3)
System.out.println("First is greatest");
else if(n2>n1 && n2>n3)
System.out.println("Second is greatest");
else
System.out.println("Third is greatest");
}
}
//Write a program to accept three sides of a triangle and check if the triangle is
equilateral, isosceles or scalene.
public class Ex7_2_2
{
static void main(int s1, int s2, int s3)
{
if(s1==s2 && s2==s3)
System.out.println("Equilateral");
else if(s1==s2 || s2==s3 || s1==s3)
System.out.println("Isosceles ");
else
System.out.println("Scalene");
}
}
//Write a program to input a number and find out if it is single digit, double digit, 8 three
digit or more than three digits. Display the output with proper messages.
public class Ex7_2_3
{
static void main(int n)
{
if(n>0 && n<10)
System.out.println("Single Digit");
else if(n>=10 && n<100)
System.out.println("Double Digit");
else if(n>=100 && n<1000)
System.out.println("Three Digit");
else
System.out.println("More than three digit number");
}
}
/*WAP to accept a number and check
1. Whether it is divisible by 3 and 7.
2. Whether it is divisible by 3 and not by 7.
3. Whether it is divisible by 7 and not by 3.
*/
public class Ex7_2_4
{
static void main(int n)
{
if(n%3==0 && n%7==0)
System.out.println("Number is divisible by 3 and 7");
else if(n%3==0 && n%7 !=0)
System.out.println("Number is divisible by 3 and not by 7");
else if(n%7==0 && n%3 !=0)
System.out.println("Number is divisible by 7 and not by 3");
}
}
Write a program to find maximum between two numbers
public class abc
{
static void main(int n1, int n2)
{
if(n1>n2)
System.out.println("First is greatest");
else
System.out.println("Second is greatest");
}
//WAP to accept a number and print whether it is positive or negative or zero
public class if2
{
static void main(int n)
{
if (n==0)
System.out.println("Number is zero");
else if(n>0)
System.out.println("Number is Positive");
else
System.out.println("Number is Negative");
}
}
//if - else statement in Java
//WAP to accept age and print eligible for voting
public class if1
{
static void main(int age)
{
if (age>=18)
System.out.println("Eligible for voting");
else
System.out.println("Not eligible for voting");
}
}
Write a Java program to accept percentage and check for the following;
• More than 35 and less than 45, display the message pass class
• More than 45 and less than 59, display the message second class
• More than or equal to 60, display first class
public class rev4
{
static void main(int p)
{
if(p>=35 && p<45)
System.out.println("Pass Class");
Else if(p>=45&& p<=59)
System.out.println("Second Class");
else
System.out.println("First Class");
}
}
Write a Java program to accept the side, base and hypotenuse from the user and check if
right angle triangle can be formed. Display proper messages. (Formula :- side*side +
base * base = hypotenuse * hypotenuse)
public class rev3
{
static void main(int s, int b, int h)
{
if( s*s + b*b == h*h)
System.out.println("Right angle triangle can be formed");
else
System.out.println("Right angle triangle cannot be formed");
}
}
//Write a program to check whether a number is even or odd
public class abc
{
public static void main(int a)
{
if(a%2==0)
System.out.println("Even Number");
else
System.out.println("Odd Number");
}
}
//Write a program to check whether a year is leap year or not
public class abc
{
public static void main(int y)
{
if(y%4==0)
System.out.println("Leap Year");
else
System.out.println("Not a Leap Year");
}
//Write a program to check whether a character is alphabet or not
public class abc
{
public static void main(char a)
{
if((a>=65&&a<=90)||(a>=97&&a<=122))
System.out.println("It is Alphabet");
else
System.out.println("It is not Alphabet");
}
Practice
//WAP to print square and cube of a number entered by the user
//WAP to print area of a rectangle by using function argument method
//WAP to print area of a circle
public class practice
{
static void main(int r)
{ float p=3.14f;
System.out.println("Area = "+(p*r*r));
}}
{
static void main(int a)
{
//int a =5;
int sq=a*a;
System.out.println("Square = "+sq);
}
}
//Mixed and Pure Expression in Java
public class PureMix
{
static void main()
{
int a=5;
int b=10;
char d='a';
float c=10.25f;
System.out.println(a+b);
System.out.println(a+c);
System.out.println(a+d);
}
}
public class ImpConcepts
{
static void main()
{
//this is to explain use of + sign
System.out.println("1 + 2 = " + 1 + 2);
System.out.println("1 + 2 = " + (1 + 2));
/*1 + 2 = 12 and 1 + 2 = 3, respectively. If either (or both) of the
operands of the + operator is a string, the other is automatically cast to a
string.*/
System.out.println(1 + 2 + "abc");
System.out.println("abc" + 1 + 2);
/**3abc and abc12, respectively. The + operator is left-to-right
associative, whether it is string concatenation or addition
*/
}
}