Assignment 2
Assignment 2
div- B
Sub-Spm
Assignment-2
1. Check if a number input by user is a multiple of 27 or not.
package javaapp1;
import java.util.Scanner;
int n;
if(n%27==0)
{
System.out.println("The Number Input by user is a multiple of 27");
}
else{System.out.println("the number input by user is not a multiple of 27");}
}
}
2. Depending on the age input by user, display if the user is a minor (0-17 yrs), adult
(18-59 yrs) or a senior citizen (60+ yrs).
package javaapp1;
import java.util.Scanner;
int age;
if(age<=17)
{
System.out.println("You are a minor");
}
else if(age<=59)
{
Name-Megh Patel
div- B
Sub-Spm
3. Input all three angles of a triangle and display if it is a valid triangle or not.
(H
int :sum of all angles of a triangle= 180°)
package javaapp1;
import java.util.Scanner;
if(a1+a2+a3==180)
{
System.out.println("It is a valid triangle");
}
else
{
System.out.println("It is not a valid triangle");
}
}
package javaapp1;
import java.util.Scanner;
if(a.length()==1)
{
System.out.println("The Character is valid");
if(a.equals("a")||a.equals("e")||a.equals("i")||a.equals("o")||a.equals("u"))
{
System.out.println("The character is a vowel");
}
else{System.out.println("The character is a consonant");}
}
else{System.out.println("The character is invalid");}
}
}
5. Input cost price and selling price of a product and determine if there is profit or loss.
Display the final amount of profit / loss.
(H
int : Profit = SP - CP and Loss= CP – SP)
package javaapp1;
import java.util.Scanner;
int sp,cp,profit,loss;
if(sp<cp)
{
System.out.println("There is a profit");
profit=sp-cp;
System.out.println("Profit="+profit);
}
else{
System.out.println("There is a loss");
loss=cp-sp;
System.out.println("Loss="+loss);
}
}