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

jaa

The document contains multiple Java programs demonstrating basic programming concepts. It includes examples for adding three numbers, converting Fahrenheit to Celsius, calculating the area and perimeter of a rectangle, determining if a number is even or odd, and finding the largest of three numbers. Each program utilizes user input and prints the results to the console.

Uploaded by

Hiya Berries
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)
16 views

jaa

The document contains multiple Java programs demonstrating basic programming concepts. It includes examples for adding three numbers, converting Fahrenheit to Celsius, calculating the area and perimeter of a rectangle, determining if a number is even or odd, and finding the largest of three numbers. Each program utilizes user input and prints the results to the console.

Uploaded by

Hiya Berries
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/ 5

JAVA PROGRAMMING

public class AddThreeNumbers {

public static void main(String[] args) {

// Declare three variables to hold the numbers

int num1 = 10;

int num2 = 20;

int num3 = 30;

// Calculate the sum of the three numbers

int sum = num1 + num2 + num3;

// Print the result

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

}
import java.util.Scanner;

public class FahrenheitToCelsius {

public static void main(String[] args) {

// Create a Scanner object to read input from the user

Scanner scanner = new Scanner(System.in);

// Ask the user to enter a temperature in Fahrenheit

System.out.print("Enter temperature in Fahrenheit: ");

double fahrenheit = scanner.nextDouble();

// Convert Fahrenheit to Celsius using the formula

double celsius = (fahrenheit - 32) * 5 / 9;

// Print the result

System.out.println("Temperature in Celsius: " + celsius);

}
import java.util.Scanner;

public class Rectangle {

public static void main(String[] args) {

// Create a Scanner object to read input from the user

Scanner scanner = new Scanner(System.in);

// Ask the user to enter the length and width of the rectangle

System.out.print("Enter the length of the rectangle: ");

double length = scanner.nextDouble();

System.out.print("Enter the width of the rectangle: ");

double width = scanner.nextDouble();

// Calculate the area of the rectangle

double area = length * width;

// Calculate the perimeter of the rectangle

double perimeter = 2 * (length + width);

// Print the results

System.out.println("Area of the rectangle: " + area);

System.out.println("Perimeter of the rectangle: " + perimeter);

}
}

import java.util.Scanner;

public class EvenOdd {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number: ");

int number = scanner.nextInt();

if (number % 2 == 0) {

System.out.println(number + " is even.");

} else {

System.out.println(number + " is odd.");

}
import java.util.Scanner;

public class LargestNumber {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter first number: ");

int num1 = scanner.nextInt();

System.out.print("Enter second number: ");

int num2 = scanner.nextInt();

System.out.print("Enter third number: ");

int num3 = scanner.nextInt();

int largest;

if (num1 >= num2 && num1 >= num3) {

largest = num1;

} else if (num2 >= num1 && num2 >= num3) {

largest

You might also like