Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Write a programming in java to display any message

The document contains several Java programming examples, including displaying messages, using various operators (increment, decrement, bitwise, arithmetic, relational), calculating the volume of a cylinder based on user input, checking if an integer is odd or even, and calculating the product of three floating-point numbers. Each example is presented with the corresponding code and explanations. The programs utilize the Scanner class for user input and demonstrate basic Java syntax and operations.

Uploaded by

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

Write a programming in java to display any message

The document contains several Java programming examples, including displaying messages, using various operators (increment, decrement, bitwise, arithmetic, relational), calculating the volume of a cylinder based on user input, checking if an integer is odd or even, and calculating the product of three floating-point numbers. Each example is presented with the corresponding code and explanations. The programs utilize the Scanner class for user input and demonstrate basic Java syntax and operations.

Uploaded by

computer tricks
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Write a programming in java to display any message

package firstp;

public class p1 {

public static void main(String[] args) {

System.out.println("on friday we will study oop");

2. Write a java program to give the example of operators


A. inclement and decrement operators

package operators;

public class op1 {

public static void main(String[] args) {

int number = 10;

number++;
System.out.println("After increment: " + number);

number--;
System.out.println("After decrement: " + number);
}

}
b. Bitwise Operator

package operators;

public class op2 {

public static void main(String[] args) {

int a = 5;
int b = 3;

int andResult = a & b;


System.out.println("a & b = " + andResult);

int orResult = a | b;
System.out.println("a | b = " + orResult);

c. Arithmetic operator

package operators;

public class op3 {

public static void main(String[] args) {

int a = 2;
int b = 8;

int sum = a + b;
System.out.println("Sum: " + sum);
int sub = a - b;
System.out.println("substraction: " + sub);

int product = a * b;
System.out.println("Product: " + product);

D. Relational Operator
package operators;

public class op4 {

public static void main(String[] args) {

int a = 4;
int b = 5;

System.out.println("a == b: " + (a == b));


System.out.println("a != b: " + (a != b));

3.calculate volume of cylinder if all parameter of cylinder are inputted by an


interactive user
Solution
package calvolumecylinder;
import java.util.Scanner;
public class test {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the radius of the cylinder: ");


double radius = scanner.nextDouble();

System.out.print("Enter the height of the cylinder: ");


double height = scanner.nextDouble();

double volume = Math.PI * Math.pow(radius, 2) * height;

System.out.println("The volume of the cylinder is: " + volume);

scanner.close();
}

4. write s java program to check if input integer is odd or even in eclipse


solution
package check;
import java.util.Scanner;

public class oddeven {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter an integer: ");


int number = scanner.nextInt();

if (number % 2 == 0) {
System.out.println("The number " + number + " is even.");
} else {
System.out.println("The number " + number + " is odd.");
}

scanner.close();

5. A java program to calculate product of 3 floating point if an inteeactive user Is


requested to in put those number
solution

import java.util.Scanner;

public class ProductCalculator {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter three floating-point numbers:");

float number1 = scanner.nextFloat();


float number2 = scanner.nextFloat();
float number3 = scanner.nextFloat();
float product = number1 * number2 * number3;

System.out.println("The product of the three numbers is: " + product);

scanner.close();
}
}

You might also like