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

Java Programming Basics and Examples

Uploaded by

Suresh Kumar
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)
29 views2 pages

Java Programming Basics and Examples

Uploaded by

Suresh Kumar
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

Hello World Check

Write a program with psvm that prints "Welcome to Java Programming".

Command Line Print

Write a program that prints all the values passed as command-line arguments.

Sum of Arguments

Write a program that takes two numbers from command line and prints their sum.

Print Program Name

Write a program that prints "This program is running from main method!".

Multiple Main Methods

Create a class with two main methods:

public static void main(String[] args)

public static void main(String arg)

See which one runs when you execute.

Print All Data Types

Declare and initialize all primitive data types (byte, short, int, long, float, double, char, boolean) and
print their values.

Arithmetic Operations

Take two integers a = 12, b = 5. Print sum, difference, product, quotient, and remainder.

Boolean Check

Declare two numbers and print whether the first is greater than the second.

Character Example
Store a character (say 'M') in a variable and print it.

Area of Circle

Declare a float variable radius = 7.5f. Print the area of the circle using formula π * r * r.

Rectangle Perimeter

Write a program that stores length and breadth in int variables and prints perimeter of rectangle.

Temperature Conversion (F → C)

Store temperature in Fahrenheit as a double and convert it to Celsius using:

C = (F - 32) * 5 / 9.

Simple Interest

Declare three variables: principal, rate, and time. Compute simple interest:

SI = (P * R * T) / 100.

Even or Odd Check

Store an integer in a variable. Print whether it is even or odd (using % operator).

You might also like