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

Practical File

This document provides 3 Java programs to demonstrate different programming concepts: 1) A program to calculate the volume of a cuboid using user input for length, width, and height. 2) A program that performs various mathematical expressions using operators, including modulo, division, addition, and post-increment. 3) A program that prints the square of every alternate number in an array.

Uploaded by

avengers9209
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Practical File

This document provides 3 Java programs to demonstrate different programming concepts: 1) A program to calculate the volume of a cuboid using user input for length, width, and height. 2) A program that performs various mathematical expressions using operators, including modulo, division, addition, and post-increment. 3) A program that prints the square of every alternate number in an array.

Uploaded by

avengers9209
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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