0% found this document useful (0 votes)
12 views2 pages

Java

The document provides three concise Java code examples: a Hello World program, a simple calculator for addition, and a program to check if a number is even or odd. Each example includes the necessary code and prompts for user input. The document encourages adaptation of these examples for various needs.

Uploaded by

chetnaspsb7e5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Java

The document provides three concise Java code examples: a Hello World program, a simple calculator for addition, and a program to check if a number is even or odd. Each example includes the necessary code and prompts for user input. The document encourages adaptation of these examples for various needs.

Uploaded by

chetnaspsb7e5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Here are three concise Java code examples for different purposes:

1. Hello World Program


Copy the codepublic class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

2. Simple Calculator (Addition)


Copy the codeimport java.util.Scanner;

public class Calculator {


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();

int sum = num1 + num2;


System.out.println("The sum is: " + sum);
}
}

3. Check if a Number is Even or Odd


Copy the codeimport 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.");
}
}
}

Feel free to adapt these examples to your needs! Let me know if you'd like help with a
specific type of Java program.

You might also like