Java Assign
Java Assign
Java Assign
Ans:
import java.util.*;
int n1=sc.nextInt();
sc.nextLine();
int n2=sc.nextInt();
sc.nextLine();
if(n1==n2)
System.out.println("Equal");
else
System.out.println("Not Equal");
}
2. Write a java program to check whether a given number is even or odd.
Ans-
import java.util.*;
int n;
n = s.nextInt();
s.nextLine();
if(n % 2 == 0)
else
4. Write a java program to find whether a given year is a leap year or not.
Ans:
import java.util.*;
public class Leap
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int lp=s.nextInt();
s.nextLine();
if(lp%400==0)
{
System.out.println("Leap year");
}
else if((lp%4==0) && (lp%100==0))
{
System.out.println("leap year");
}
else
{
System.out.println("not a leap year");
}
}
}
5. Write a java program to read the age of a candidate and determine whether it is eligible for
casting his/her own vote.
Ans:
import java.util.*;
int a=s.nextInt();
s.nextLine();
if(a>=18)
System.out.println("Eligible");
else
System.out.println("Not Eligible");
}
6. Write a Java program to accept the height of a person in centimeter and categorize the
person according to their height.
Ans:
import java.util.*;
int h;
h = s.nextInt();
s.nextLine();
System.out.println("tall");
System.out.println("average height");
else
System.out.println("dwarf");
}
Ans:
Import java.util.*;
int a,b,c;
a=sc.nextInt();
sc.nextLine();
b=sc.nextInt();
sc.nextLine();
c=sc.nextInt();
sc.nextLine();
System.out.println("a is greater");
}
System.out.println("b is greater");
else
System.out.println("c is greater");
8. Write a Java program to find the eligibility of admission for a professional course based on
the following criteria: Eligibility Criteria : Marks in Maths >=65 and Marks in Phy >=55 and
Marks in Chem>=50 and Total in all three subject >=190 or Total in Maths and Physics >=140
------------------------------------- Input the marks obtained in Physics :65 Input the marks
obtained in Chemistry :51 Input the marks obtained in Mathematics :72 Total marks of
Maths, Physics and Chemistry : 188 Total marks of Maths and Physics : 137 The candidate is
not eligible.
Ans:
import java.util.*;
sc.nextLine();
sc.nextLine();
sc.nextLine();
System.out.println("Eligible");
else
System.out.println("Not Eligible");
}
9. Write a Java program to read roll no, name and marks of three subjects and calculate the
total, percentage and division.
Ans:
import java.util.*;
int m1 = sc.nextInt();
int m2 = sc.nextInt();
int m3 = sc.nextInt();
div = "First";
div = "Second";
else
div = "Fail";
}
}
10. Write a Java program to read temperature in centigrade and display a suitable message
according to temperature state below : Temp < 0 then Freezing weather Temp 0-10 then
Very Cold weather Temp 10-20 then Cold weather Temp 20-30 then Normal in Temp Temp
30-40 then Its Hot Temp >=40 then Its Very Hot
Ans:
import java.util.*;
class TemperatureC
sc.nextLine();
if(temp < 0)
System.out.println("Freezing Weather");
System.out.println("Very Cold");
System.out.println("Cold");
System.out.println("Normal Weather");
System.out.println("Hot Temperature");
else if(temp>=40)
System.out.println("Very Hot");
}
11. Write a Java program to check whether a triangle is Equilateral, Isosceles or Scalene.
import java.util.*;
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
System.out.println("equilateral triangle");
System.out.println("Isosceles triangle");
else
System.out.println("Scaler triangle");
}
12. Write a Java program to check whether a character is an alphabet, digit or special character.
Ans:
import java.util.*;
char ch;
ch=p.next().charAt(0);
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
System.out.println(ch+" is Alphabit");
else if(ch>='0'&&ch<='9')
System.out.println(ch+" is Digit");
else
{
13. Write a Python program to check whether a triangle can be formed by the given value for
the angles.
Ans:
import java.util.*;
class Angle
{
public static void main(String args[])
{
}
}
14. Write a Python program to check whether an alphabet is a vowel or consonant.
Ans:
import java.util.*;
char ch;
ch=sc.next().charAt(0);
else
}
15. Write a Java program to calculate profit and loss on a transaction.
Ans:
import java.util.*;
class ProfitandLoss
double cp=s.nextDouble();
double sp=s.nextDouble();
if(cp-sp>0)
System.out.println("loss:" +(cp-sp));
else if(cp-sp<0)
System.out.println("profit:" +(sp-cp));
else
System.out.println("NEUTRAL");
}
16. Write a program in Python to accept a grade and declare the equivalent description : Grade
Description E Excellent V Very Good G Good A Average F Fail
Ans:
import java.util.*;
public class Grade
{
public static void main(String[] args)
{
char a;
Scanner sc = new Scanner(System.in);
System.out.print("Enter grade of the student:");
a = sc.next().charAt(0);
if(a == 'E' || a == 'e')
{
System.out.println("Excelent");
}
else if(a == 'V' || a == 'v')
{
System.out.println("Very Good");
}
else if(a == 'G' || a == 'g')
{
System.out.println("Good");
}
else if(a == 'E' || a == 'e')
{
System.out.println("Average");
}
else if(a == 'F' || a == 'f')
{
System.out.println("Average");
}
}
}
17. Write a program in Java to calculate and print the Electricity bill of a given customer. The
customer id., name and unit consumed by the user should be taken from the keyboard and
display the total amount to pay to the customer. The charge are as follow : Unit Charge/unit
upto 199 @1.20 . 200 and above but less than 400 @1.50 400 and above but less than 600
@1.80 600 and above @2.00 If bill exceeds Rs. 400 then a surcharge of 15% will be charged
and the minimum bill should be of Rs. 100/-
Ans:
import java.util.*;
void calculate()
if(units<=199)
bill = 1.20*units;
else if(units>=600)
}
if(bill>400)
n = sc.nextLine();
units = sc.nextInt();
obj.calculate();
}
18. Write a program in java to read any day number in integer and display day name in the
word.
Ans:
import java.util.*;
if(weekday == 1)
System.out.println("Monday");
else if(weekday == 2)
System.out.println("Tuesday");
else if(weekday == 3)
System.out.println("Wednesday");
else if(weekday == 4)
System.out.println("Thursday");
else if(weekday == 5)
System.out.println("Friday");
}
else if(weekday == 6)
System.out.println("Saturday");
else if(weekday == 7)
System.out.println("Sunday");
else
19. Write a program in java to read any Month Number in integer and display Month name in
the word.
Ans:
import java.util.*;
if(month == 1)
System.out.println("January");
else if(month == 2)
System.out.println("February");
else if(month == 3)
System.out.println("March");
else if(month == 4)
System.out.println("April");
else if(month == 5)
System.out.println("May");
else if(month == 6)
System.out.println("June");
else if(month == 7)
System.out.println("July");
else if(month == 8)
{
System.out.println("August");
else if(month == 9)
System.out.println("September");
System.out.println("October");
System.out.println("November");
System.out.println("December");
else
System.out.println("Invalid month");
}
20. Write a program in Java to read any Month Number in integer and display the number of
days for this month.
Ans:
import java.util.*;
int number_Of_Days = 0;
switch (month) {
case 1:
Month = "January";
number_Of_Days= 31;
break;
case 2:
Month = "February";
number_Of_Days = 29;
} else {
number_Of_Days = 28;
break;
case 3:
Month = "March";
Number_Of_Days = 31;
break;
case 4:
Month= "April";
number_Of_Days = 30;
break;
case 5:
Month = "May";
number_Of_Days = 31;
break;
case 6:
Month = "June";
number_Of_Days = 30;
break;
case 7:
Month = "July";
number_Of_Days = 31;
break;
case 8:
Month = "August";
number_Of_Days= 31;
break;
case 9:
Month = "September";
number_Of_Days = 30;
break;
case 10:
Month = "October";
number_Of_Days = 31;
break;
case 11:
Month = "November";
number_Of_Days = 30;
break;
case 12:
Month = "December";
number_Of_Days= 31;