12-IT Java Programms
12-IT Java Programms
Class: XII
Topic: Practical File
Subject: Information Technology (802) Term-II
1. Write a program to calculate percentage calculator program, using three variables named
marks_obtained, total_marks and percentage.
2. Write a program to store textual data, for example, the name of a student Mayank M Saxena).
3. Write a program to demonstrates usage of the switch statement for finding week day.
8. Write a program to find out how many elements an array has, use the length property:
public static void main(String[] args) {
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
System.out.println(cars.length);
}
9. Write a program to create a two-dimensional array, add each array within its own set of curly
braces:
public static void main(String[] args) {
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
int x = myNumbers[1][2];
System.out.println(x); }
10. Write a program to use a for loop inside another for loop to get the elements of a two-
dimensional array
public static void main(String[] args) {
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
for (int i = 0; i < myNumbers.length; ++i) {
for(int j = 0; j < myNumbers[i].length; ++j) {
System.out.println(myNumbers[i][j]);} }
11. Write a program to store five marks in the array
double[]marks = {346, 144, 103, 256.5, 387.5};
double total_marks = 400;
System.out.println("\tClass Report");
System.out.println("--------------------------------------");
System.out.println("RollNo\tMarks\tPercentage\tResult");
System.out.println("--------------------------------------");
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);}
13. Write a program to check Age using call a method with an integer parameter.
// Create a checkAge() method with an integer parameter called age
static void checkAge(int age) {
// If age is less than 18, print "access denied"
if (age < 18) {
System.out.println("Access denied - You are not old enough!");
14. Write a program using Wrapper classes to provide a way to use primitive data types (int,
boolean, etc..) as objects.
public class Main {
public static void main(String[] args) {
Integer myInt = 5;
Double myDouble = 5.99;
Character myChar = 'A';
System.out.println(myInt);
System.out.println(myDouble);
System.out.println(myChar); }
15. Write a JAVA program to convert an Integer to a String, and use the length() method of the
String class to output the length of the "string":
public class Main {
public static void main(String[] args) {