import [Link].
Scanner;
public class Demo1
{
public static void main(String[] args)
{
String sname;
int rollno;
float cgpa;
Scanner sc=new Scanner([Link]);
[Link]("Enter your full name");
sname=[Link]();
[Link]("Enter your rollno");
rollno=[Link]();
[Link]("Enter your cgpa score");
cgpa=[Link]();
[Link]("Name: "+sname);
[Link]("Rollno:"+rollno);
[Link]("CGPA Score:"+cgpa);
}
}
==============================================================================
import [Link];
public class Demo2 {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of employees");
int count = [Link]();
[Link](); // consume the newline
int empId;
double empbSal, annualbSal = 0, hra = 0, da = 0, pf = 0, gmsal = 0, nmsal =
0, ansal = 0;
String empName;
double maxAns = Double.MIN_VALUE;//4.9E-324
double minAns = Double.MAX_VALUE;//1.7976931348623157E308
//[Link]("maxAns= "+maxAns);
//[Link]("minAns= "+minAns);
String maxEmp = "", minEmp = "";
for (int i = 1; i <= count; i++)
{
[Link]("Enter employee Id:");
empId = [Link]();
[Link](); // consume the newline after nextInt
[Link]("Enter employee Name:");
empName = [Link]();
[Link]("Enter employee basic salary:");
empbSal = [Link]();
[Link](); // optional: consume newline if mixing inputs
if (empbSal > 0) {
annualbSal = 12 * empbSal;
hra = 0.2 * empbSal;
da = 0.1 * empbSal;
pf = 0.12 * empbSal;
gmsal = empbSal + hra + da;
nmsal = gmsal - pf;
ansal = nmsal * 12;
}
if (ansal > maxAns) {
maxAns = ansal;
maxEmp = empName + " (ID: " + empId + ")";
}
if (ansal < minAns)
{
minAns = ansal;
minEmp = empName + " (ID: " + empId + ")";
}
[Link]("\n--- Employee Details ---");
[Link]("Employee ID: " + empId);
[Link]("Employee Name: " + empName);
[Link]("Basic Salary: " + empbSal);
[Link]("Annual Basic Salary: " + annualbSal);
[Link]("HRA: " + hra);
[Link]("DA: " + da);
[Link]("PF: " + pf);
[Link]("Gross Monthly Salary: " + gmsal);
[Link]("Net Monthly Salary: " + nmsal);
[Link]("Annual Net Salary: " + ansal);
[Link]("--------------------------\n");
}
// Display the highest and lowest annual net salary
[Link]("Employee with Highest Annual Net Salary: " + maxEmp + "
=> Rs." + maxAns);
[Link]("Employee with Lowest Annual Net Salary: " + minEmp + "
=> Rs." + minAns);
// [Link](); // always good practice to close scanner
}
}
==========================================================================
/*
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
*/
import [Link];
public class Demo1
{
public static void main(String[] args)
{
int rows,count=1;
Scanner sc=new Scanner([Link]);
[Link]("Enter the number of rows");
rows=[Link]();
for(int i=1;i<=rows;i++)
{
for(int j=1;j<=i;j++)
{
[Link](" "+count);
count++;
}
[Link]();
}
}
}
==========================================================================
/*
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
*/
import [Link];
public class Demo2
{
public static void main(String[] args)
{
int rows,count=1;
Scanner sc=new Scanner([Link]);
[Link]("Enter the number of rows");
rows=[Link]();
for(int i=1;i<=rows;i++)
{
for(int j=1;j<=i;j++)
{
[Link](" "+count);
count=count+2;
}
[Link]();
}
}
}
=================================================================================
/*
1
2 3
4 * 6
7 8 9 *
11 12 13 14 *
*/
import [Link];
public class Demo3
{
public static void main(String[] args)
{
int rows,count=1;
Scanner sc=new Scanner([Link]);
[Link]("Enter the number of rows");
rows=[Link]();
for(int i = 1; i <= rows; i++)
{
for(int j = 1; j <= i; j++)
{
if (count % 5 == 0)
{
[Link]("* ");
}
else
{
[Link](count + " ");
}
count++;
}
[Link]();
}
}
}
===============================================================================
=================================================================================
import [Link];
public class Demo5
{
public static void main(String[] args)
{
int rollno;
float sub1,sub2,sub3,sub4,sub5,totmarks=0,avg=0,percent=0;
String sname,grade;
Scanner sc=new Scanner([Link]);
[Link]("Enter roll number of Student");
rollno=[Link]();
[Link]();
[Link]("Enter name of a student");
sname=[Link]();
[Link]("Enter marks of five subjects");
sub1=[Link]();
sub2=[Link]();
sub3=[Link]();
sub4=[Link]();
sub5=[Link]();
if(sub1<=100 && sub2<=100 && sub3<=100 && sub4<=100 && sub5<=100)
{
totmarks=sub1+sub2+sub3+sub4+sub5;
avg=totmarks/5;
percent=(totmarks/500)*100;
}else
{
[Link]("Please enter marks less than 100");
}
if(avg>=90 && avg<=100)
{
grade="A";
}else if(avg>=80 && avg<=89)
{
grade="B";
}else if(avg>=70 && avg<=79)
{
grade="C";
}else if(avg>=60 && avg<=69)
{
grade="D";
}else
{
grade="E";
}
[Link]("Name:"+sname);
[Link]("Roll number:"+rollno);
[Link]("Total Marks:"+totmarks);
[Link]("Average Marks:"+avg);
[Link]("Grade:"+grade);
[Link]("Percentage:"+percent);
switch(grade)
{
case "A":
[Link]("Excellent");
break;
case "B":
[Link]("Very Good");
break;
case "C":
[Link]("Good");
break;
case "D":
[Link]("Satisfactory");
break;
case "E":
[Link]("Needs Improvement");
break;
default:
[Link]("invalid grade");
}
}/*
Enter roll number of Student
1
Enter name of a student
Reshma Salunkhe
Enter marks of five subjects
40
50.5
60
70.5
80
Name:Reshma Salunkhe
Roll number:1
Total Marks:301.0
Average Marks:60.2
Grade:D
Percentage:60.2
Satisfactory
*/
=================================================================================
class BankAccount
{
float balance;
String account_number;
public float getBalance()
{
return balance;
}
public void setBalance(float balance)
{
[Link] = balance;
}
public String getAccount_number()
{
return account_number;
}
public void setAccount_number(String account_number) {
this.account_number = account_number;
}
public void withdraw(float wamt)
{
if(balance<wamt)
{
[Link]("insufficient balance");
}else
{
balance=balance-wamt;
[Link]("Balance After withdraw:"+balance);
}
public void deposit(float damt)
{
balance=balance+damt;
[Link]("Balance After deposit:"+balance);
}
}
public class Test
{
public static void main(String[] args)
{
BankAccount acc=new BankAccount();
acc.setAccount_number("012416231000466");
[Link](500);
[Link](acc.getAccount_number());
[Link]([Link]());
[Link](400);
[Link](100);
}
}
/*
012416231000466
500.0
Balance After withdraw:100.0
Balance After deposit:200.0
*/
================================================================================