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

Java Programs: Main Args Println

The document discusses Java programs that demonstrate different programming concepts. It includes 3 programs: 1) A program that defines a Phone class with final price variables and method to illustrate final keyword usage. 2) A simple program that checks if variable b is greater than a using an if statement. 3) Another program that checks if b is greater than a, and if not prints that a is greater, demonstrating an if-else statement.

Uploaded by

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

Java Programs: Main Args Println

The document discusses Java programs that demonstrate different programming concepts. It includes 3 programs: 1) A program that defines a Phone class with final price variables and method to illustrate final keyword usage. 2) A simple program that checks if variable b is greater than a using an if statement. 3) Another program that checks if b is greater than a, and if not prints that a is greater, demonstrating an if-else statement.

Uploaded by

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

Java programs

public class Hello


{
public static void main(String[] args)
{
System.out.println("Hello Java");
}
}
Variable Data Types
class DataTypes
{
public static void main(String args[])
{
byte byteVar = 5;
short shortVar = 20;
int intVar = 30;
long longVar = 60;
float floatVar = 20;
double doubleVar = 20.123;
boolean booleanVar = true; char charVar ='W';
System.out.println("Value Of byte Variable is " + byteVar);
System.out.println("Value Of short Variable is " + shortVar);
System.out.println("Value Of int Variable is " + intVar);
System.out.println("Value Of long Variable is " + longVar);
System.out.println("Value Of float Variable is " + floatVar);
System.out.println("Value Of double Variable is " + doubleVar);
System.out.println("Value Of boolean Variable is " + booleanVar);
System.out.println("Value Of char Variable is " + charVar); } }
Program 1

class Phone {
final int PRICE_MIN = 999;
final int PRICE_MAX = 5600; //final variable
final void display() //final method
{
System.out.println("Min Price is" + PRICE_MIN);
System.out.println("Max Price is" + PRICE_MAX ); } }

Program 2
public class Sample
{
public static void main(String args[])
{
int a=20, b=30;
if(b>a)
System.out.println("b is greater"); } }

Program 3
public class Sample
{
public static void main(String args[])
{
int a = 80, b = 30;
if (b > a)
{
System.out.println("b is greater");
}
else
{
System.out.println("a is greater"); } } }

You might also like