Practical File

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

INFORMATION TECHNOLOGY

PROGRAMS OF JAVA
FOR
PRACTICAL FILE
CLASS -12
TERM-2
Program1: Write a program in Java to implement the formula: Volume = length * width * height.

import java.util.Scanner;

public class Volume {

public static void main (String[ ] args) {

Scanner user_input = new Scanner(System.in);

System.out.println(“Enter length of cuboid”);

String length = user_input.next();

double l= Double.parseDouble(length);

System.out.println(“Enter breadth of cuboid”);

String breadth = user_input.next();

double b= Double.parseDouble(breadth);

System.out.println(“Enter height of cuboid”);

String height = user_input.next();

double h= Double.parseDouble(height);

double Volume=l*b*h;

System.out.println(“Volume of cuboid: “ +Volume);

Output
Program2: Write a program in Java to find the result of the following expressions. (Assume a = 20 and b = 30)

i) a%b

ii) a /= b

iii) (a + b * 100) /10

iv) a++

public class TestOperators {

public static void main (String[ ] args) {

int a=20;

int b=30;

System.out.println(“The result of a%b is : “ +(a%b));

System.out.println(“The result of a/=b is : “ +(a/=b));

System.out.println(“The result of (a+b*100)/10 is : “ +((a+b*100)/10));

System.out.println(“The result of a++ is : “ +(a++));

Output:
Program 3: Write a program in Java to print the square of every alternate number of an array

public class AlternateArray {

public static void main (String[ ] args) {

int [] numbers = {10, 20, 14, 12, 1, 8, 40, 90, 100, 7};

for (int i = 0; i < numbers.length; i=i+2)

System.out.println(numbers[i]*numbers[i]);

You might also like