0% found this document useful (0 votes)
290 views

Holiday Homework

Holiday homework class 12th 2024
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)
290 views

Holiday Homework

Holiday homework class 12th 2024
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/ 17

JAVA Practical File

2024-25

YEAR 2024-25

JAVA NETBEANS

Submitted By: Submitted To:


CERTIFICATE
CLASS: Xii- YEAR:2024-25

This is to certify that Investigatory Project is


successfully completed by …..……………………………………………. of
Class: XII .Roll no. : …………………………... for the academic year
2024-25 in the School Computer lab.

External Examiner Internal Examiner


Signature: (Subject Teacher)

Date: / / 25 Department of COMPUTER SCIENCE

PRINCIPAL
Acknowledgement

I …………………………… of class XIITH Roll no………………

would like to express my sincere gratitude to my computer science

teacher Mr. BHAVAM BHANDARI, PGT COMPUTER SCIENCE, for his

vital support, guidance and encouragement – without which this project

would not have come forth.

I would also like to express my gratitude to my school St. Mary’s Senior


Secondary School for letting me use the school laboratory.
Index
1. Program to print “Hello Java” in Java Programming.
2. Program to print multiple lines in Java and use of “println()”.
3. Program to print Simple Interest, Principle, Rate of Interest and Time is user
given value.
4. Program to print Student’s percentage after getting marks.
5. Program to use the conditional statement in Java Programming.
6. Program to show the use of if else ladder in Java Programming.
7. Program to show the use of if else with conditional operator.
8. Program to take user five subject marks and print the Total marks and
Percentage with a message.
9. Program to show the use of switch and case in Java programming.
10.Program to print the number 1 to 10 by the help of for loop in Java
Programming. Use of “\t” (to insert tab space)
11.Program to print a pattern with the help of for loop in nested condition.
12.Program to print the number between 1 to 10. By the help of while loop in
Java Programming.
13.Program to print the square root of 1 to 5.
14.Program to print the reverse counting with the help of while loop.
15.Program to print the square root of given number with the of do-while loop.
16.Program to use switch case to make calculator.
17.Program to use the user defined function/methods.
18.Program to access a particular value from an arrays.
19.Program to illustrate the another method to use arrays.
20.Program to use an array to print class report card for five students.
21.Program to make user defined class in Java Programming.
22.Program to show the use of arrays manipulation.
23.Program to use binary Search in java Programming.
24.Program to show string built-in functions:
25.Program to accept user input during the execution of program.
1. Program to print “Hello Java”.
package hellojava;
public class HelloJava {
public static void main(String[] args) {
// TODO code application logic here
System.out.print("Hello Java");
}

OUTPUT

2. Program to print multiple lines in Java and use of “println()”.


public class HelloJava {

public static void main(String[] args) {


System.out.println("Helloooo Javaaaa");
System.out.println("This is my first program");
System.out.println("Wow I have done!!!!");
}
} OUTPUT

3. Program to print Simple Interest, Principle, Rate of Interest and Time is user
given value.
public class INTREST {
public static void main(String[] args)
{
System.out.println("Insert value");
int p=5000;
int t=3;
float R=0.2f;
float si=(p*t*R)/100;
System.out.println("Result="+si);
}}
OUTPUT

4. Program to print Student’s percentage after getting marks.


public class Percentage {
public static void main(String[] args)
{
int total=400;
double marks_get=346;
double percentage=0.0;
percentage=(marks_get/total)*100;
System.out.println("Student Percentage is="+percentage);
}
} OUTPUT

5. Program to use the conditional statement in Java Programming.


public class Result {
public static void main(String[] args)
{
double percentage=85;
if (percentage >= 40) {
System.out.println("PASSED");
}
else{
System.out.println("Fail");
}
}
} OUTPUT
6. Program to show the use of if else ladder in Java Programming.
public class Remark {
public static void main(String[] args)
{
double percentage=35;
if (percentage >= 75)
{
System.out.println("Excellent");
}
else if (percentage>=40)
{
System.out.println("Passed");
}
else
{
System.out.println("Fail");
}
}
} OUTPUT:

7. Program to show the use of if else with conditional operator.


public class Rank {
public static void main(String[] args)
{
float percentage=85;

if (percentage >= 60) {


System.out.println("PASSED with I Division ");
}
else if ((percentage >= 40)&& (percentage < 60)) {
System.out.println("PASSED with II Division");
}
else{
System.out.println("FAILED"); }
}} OUTPUT:
8. Program to take user five subject marks and print the Total marks and
Percentage with a message.
public class Distinction {
public static void main(String[] args)
{
int Eng=80, Math=90, Phys=91, Chem=95, Phy_edu=95;
float total=Eng+Math+Phys+Chem+Phy_edu;
float per=total/5;
System.out.println("Total Marks=" +total+
"\nPercentage="+per);
if ((per>=40)&&(per<=59)) {
System.out.println("Second Divsion");}
else if ((per>=60)&&(per<=74)) {
System.out.println("First Divsion");}
else if (per>=75){
System.out.println("PASSED with I Division with distinction ");
}
else {
System.out.println("Fail");
}}}
OUTPUT:

9. Program to show the use of switch and case in Java programming.


public class Daysofweek {
public static void main(String[] args)
{
int today = 5;
String day = "";
switch (today) {
case 1: day = "Monday";
break;
case 2: day = "Tuesday";
break;
case 3: day = "Wednesday";
break;
case 4: day = "Thursday";
break;
case 5: day = "Friday";
break;
case 6: day = "Saturday";
break;
case 7: day = "Sunday";
break;
default: day = "Incorrect Day!";
break;
}
System.out.println (day);
}
} OUTPUT:

10. Program to print the number 1 to 10 by the help of for loop in Java
Programming. Use of “\t” (to insert tab space)
public class counting {
public static void main(String[] args)
{
for(int i=1;i<=10;i++)
{
System.out.print(i+"\t");
}
}
}
OUTPUT:

11. Program to print a pattern with the help of for loop in nested condition.
public class pattern {
public static void main(String[] args)
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
}}
OUTPUT:

12. Program to print the number between 1 to 10. By the help of while loop in
Java Programming.
public class count
{
public static void main(String[] args)
{
int number = 1;
while (number <= 10)
{
System.out.print(number+"\t");
number++;
}
}
} OUTPUT

13. Program to print the square root of 1 to 5.


public class squareofnumber {
public static void main(String[] args)
{
int number = 1;
while (number <= 5)
{
System.out.print ("Square of " + number);
System.out.println (" = " + number*number);
++number;
}
}}
OUTPUT:

14. Program to print the reverse counting with the help of while loop.
public class revcounting{
public static void main(String[] args){
int number = 5;
while (number >= 1)
{
System.out.println (number);
number--;
}
}
}
OUTPUT:

15. Program to print the square of given number with the of do-while loop.
public class Nsquare
{
public static void main(String[] args){
int number = 1;
do {
System.out.print ("Square of " + number);
System.out.println (" = " + number*number);
++number;
} while (number <= 5);
}
}
OUTPUT:

16. Program to use switch case to make calculator.


import java.util.*;
public class calculator{
public static void main(String[] args){
double num1, num2;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first number:");
num1 = scanner.nextDouble();
System.out.print("Enter second number:");
num2 = scanner.nextDouble();
System.out.print("Enter an operator (+, -, *, /): ");
char operator = scanner.next().charAt(0);
scanner.close();
double output;
switch(operator)
{
case '+':
output = num1 + num2;
break;
case '-':
output = num1 - num2;
break;
case '*':
output = num1 * num2;
break;
case '/':
output = num1 / num2;
break;
default:
System.out.printf("You have entered wrong operator");
return;
}
System.out.println(num1+" "+operator+" "+num2+": "+output);
}
}
OUTPUT:

17. Program to use the user defined function/methods.


public class Function {
public static void main(String[] args) {
int a=20, b=10;
int c=0;
c=sum(a,b);
System.out.println("Sum="+c);
int z=0;
z=sub(a,b);
System.out.print("Substract="+z);
}
static int sum(int x,int y)
{
return(x+y);
}
static int sub(int x,int y)
{
return(x-y);
}
}
OUTPUT:

18. Program to access a particular value from an array.


public class Arrays {
public static void main(String[] args) {
int ar[]={10,2,50,60,3};
System.out.println(ar[2]);
}
}
OUTPUT:
19. Program to illustrate another method to use arrays.
public class Arrays {
public static void main(String[] args) {
int ar[]=new int[5];
ar[0]=10;
ar[1]=20;
ar[2]=30;
ar[3]=40;
ar[4]=50;
for (int i=0;i<5;i++)
{
System.out.println(ar[i]);
}
} OUTPUT:
}

20. Program to use an array to print class report card for five students.
public class Arrays {
public static void main(String[] args) {
double[]marks = {346, 144, 103, 256.5, 387.5};
double total_marks=400;
for (int i = 0; i <marks.length; i++){
double percentage = (marks[i]/total_marks)*100;
String result;
if (percentage >= 40)
result = "Passed";
else
result = "Failed";
System.out.print((i+1)+"\t");
System.out.print(marks[i]+"\t");
System.out.print(percentage+"\t\t");
System.out.println(result);
}
}
}
OUTPUT:
21. Program to make user defined class in Java Programming.
public class Jvclass {
String title;
String publisher;
String author;
double price;
void display(){
System.out.println("Title="+title);
System.out.println("Author="+author);
System.out.println("Publisher="+publisher);
System.out.println("Price="+price);}
public static void main(String[] args) {
Jvclass obj=new Jvclass();
obj.title="Game of Thrones";
obj.author="Harper Collins";
obj.publisher="George R Martin";
obj.price=450.0;
obj.display();
}
}
OUTPUT:

22. Program to show the use of arrays manipulation.


import java.util.Arrays;
public class ArraysManipulation {
public static void main(String[] args) {
String[] names=
{"Sleepy","Doc","Happy","Grumpy","Banita","Richard","Colman","Anny"};
System.out.println("Names Before Sorting:");
for (int i=0; i<names.length;i++)
System.out.print(names[i]+",");
System.out.println();
Arrays.sort(names);
System.out.println("Names After Sorting:");
for (int i=0;i<names.length;i++)
System.out.print(names[i]+",");
System.out.println();

}}
OUTPUT:

23. Program to use binary Search in java Programming.


import java.util.Arrays;
import java.util.Scanner;
public class ArraysManipulation {
public static void main(String[] args) {
double[] marks= {346,144,103,256.5,387.5};
Scanner user_input=new Scanner(System.in);
System.out.print("Enter number to search=");
int key=Integer.parseInt(user_input.next());
int index=Arrays.binarySearch(marks, key);
if (index!=-1)
System.out.println("Eelment found at positiion="+(index+1));
else
System.out.println("Element not found");
}
}
OUTPUT:

24. Program to show string built-in functions:


public class StringManipulation {
public static void main(String[] args) {
String mystr="Hello Java";
System.out.println("Given String: "+mystr);
System.out.println("Char on 6th: "+mystr.charAt(6));
System.out.println("Concat Today: "+mystr.concat(" Today"));
System.out.println("Contain Hell: "+mystr.contains("Hell"));
System.out.println("End with Java: "+mystr.endsWith("Java"));
System.out.println("Compare with Old is Gold: "+mystr.equals("Old
is gold"));
System.out.println("Compare with ignore case:
"+mystr.equalsIgnoreCase("hello java"));
System.out.println("Know the string length: "+mystr.length());}}
OUTPUT

25. Program to accept user input during the execution of program.


import java.util.Scanner;
public class Userinput {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
System.out.print("Enter Your name: ");
String name = user_input.next();
System.out.println("Hello "+ name);
System.out.print("Enter Your age: ");
String age_string = user_input.next( );
int age = Integer.parseInt(age_string);
System.out.print("In 5 years you will be "+ (age +5));
System.out.println(" years old.");
}
}
OUTPUT:

You might also like