0% found this document useful (0 votes)
13 views14 pages

JAVA PGM 1-9

The document contains a series of Java programs demonstrating various programming concepts, including printing messages, performing arithmetic operations, calculating areas, and determining conditions like leap years and triangle validity. Each program includes code snippets and their expected outputs. Additionally, it features a program for calculating electricity bills based on consumer type and usage.
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)
13 views14 pages

JAVA PGM 1-9

The document contains a series of Java programs demonstrating various programming concepts, including printing messages, performing arithmetic operations, calculating areas, and determining conditions like leap years and triangle validity. Each program includes code snippets and their expected outputs. Additionally, it features a program for calculating electricity bills based on consumer type and usage.
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
You are on page 1/ 14

PROGRAM NUMBER 1

CODE:
class Main
{
public static void main(String[] args)
{
System.out.println("Welcome to Java, Learning Java now and programming is
fun");
}
}
OUTPUT:
PROGRAM NUMBER 2
WAP to print your address i) using single print ii) using multiple println

CODE:
class Main
{
public static void main(String[] args)
{
System.out.println("Using single print:");
System.out.print("ARYAN KUMAR \n AMITY UNIVERSITY
NOIDA\nNOIDA, UTTAR PRADESH-201313");
System.out.println("ARYAN KUMAR");
System.out.println("Using multiple println:");
System.out.println("AMITY UNIVERSITY NOIDA");
System.out.println("NOIDA, UTTAR PRADESH-201313");
}
}
OUTPUT:
PROGRAM NUMBER 3
WAP to print addition of 2 numbers
CODE:
class Main
{
public static void main(String[] args)
{
int a=5+10;
System.out.println("Sum of 5 and 10 is "+a);
}
}
OUTPUT;
PROGRAM NUMBER 4
WAP to calculate Area of Circle.
CODE:
class Main
{
public static void main(String[] args)
{
int r=10;
double area=3.14*r*r;
System.out.println("area of circle is "+area);
}
}

OUTPUT:
PROGRAM NUMBER 5
WAP to convert temperature from Fahrenheit to Celsius

CODE:
class Main
{
public static void main(String[] args)
{
int far=36;
double celsius = (far - 32) * 5 / 9;
System.out.println("36 degree in celsius is "+celsius);
}
}

OUTPUT:
PROGRAM NUMBER 6
• In a company an employee is paid as under:
• If his basic salary is less than Rs. 1500, then HRA = 10% of basic
salary and DA = 90% of basic salary.
• If his salary is either equal to or above Rs. 1500, then HRA = Rs.
500 and DA = 98% of basic salary.
Employee's salary is input through the keyboard, write a program to
find his gross salary.
CODE:

import java.util.*;
public class Main
{
public static void main(String[] args) {
double da,hra,gross;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the employee's basic salery");
int sal=sc.nextInt();
if(sal<=0)
{
System.out.println("INVALID SALERY");
System.exit(0);
}
if(sal<1500)
{
da=(0.9*sal);
hra=0.9*sal;
}
else
{
hra=500;
da=0.98*sal;
}
gross=da+hra;
System.out.println("Gross Salery of employee salery="+gross);

}
}
OUTPUT:
PROGRAM NUMBER 7
Any year is entered through the keyboard, write a program to
determine whether the year is leap or not.
CODE:
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)throws IOException {

Scanner sc=new Scanner(System.in);


System.out.println("Enter the year");
int year=sc.nextInt();
if(year%4==0){
if(year%100!=0 || year%400==0){
System.out.println("The year is leap year");
}
else
{
System.out.println("The year is not leap year");
}
}
}
}
OUTPUT:
PROGRAM NUMBER 8
Write a program to check whether a triangle is valid or not, when the
three angles of the triangle are entered through the keyboard. A
triangle is valid if the sum of all the three angles is
equal to 180 degrees.
CODE:
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)throws IOException {
double a1,a2,a3;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the three angles for triangle respectively");
a1=sc.nextInt();
a2=sc.nextInt();
a3=sc.nextInt();
if(a1+a2+a3==180)
{
System.out.println("The Triangle is valid Triangle");
}
else{
System.out.println("The Triangle is not valid");
}
}
}
OUTPUT:
PROGRAM NUMBER 9
1. Develop a Java application to generate Electricity bill. Create a class with the following
members: Consumer no., consumer name, previous month reading, current month reading,
type of EB connection (i.e domestic or commercial). Compute the bill amount using the
following tariff.
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
First 100 units - Rs. 1 per unit
101-200 units - Rs. 2.50 per unit
201-500 units - Rs. 4 per unit
> 501 units - Rs. 6 per unit
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
First 100 units - Rs. 2 per unit
101-200 units - Rs. 4.50 per unit
201-500 units - Rs. 6 per unit
> 501 units - Rs. 7 per unit
CODE:
import java.io.*;
import java.util.*;
public class Main
{

public static void main(String[] args)throws IOException


{
int Consumer_no;
String consumer_name;
double previous_month_reading;
double current_month_reading;
int type;
double units;
double price=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the consumer number");
Consumer_no=sc.nextInt();
System.out.println("Enter the consumer name");
consumer_name=sc.next();
System.out.println("Enter the previous month reading");
previous_month_reading=sc.nextInt();
System.out.println("Enter the current month reading");
current_month_reading=sc.nextInt();
System.out.println("Enter the type of connection 1.domestic/2.commercial in
numbers");
type=sc.nextInt();
units=current_month_reading-previous_month_reading;
if(type==1)
{
if(units<=100){
price=1*units;
}
else if(units>100 && units<=200){
price=1*units+2.5*(units-100);
}
else if(units>200 && units<=500){
price=1*units+2.5*(units-100)+4*(units-200);
}
else if(units>500 ){
price=1*units+2.5*(units-100)+4*(units-200)+6*(units-500);
}
}
if(type==2)
{
if(units<=100){
price=2*units;
}
else if(units>100 && units<=200){
price=2*units+4.5*(units-100);
}
else if(units>200 && units<=500){
price=2*units+4.5*(units-100)+6*(units-200);
}
else if(units>500 ){
price=2*units+4.5*(units-100)+6*(units-200)+7*(units-500);
}

}
System.out.println("Total price=" +price);

}
}
OUTPUT:

You might also like