Sunteți pe pagina 1din 11

Sample Programs:

Integers:
- The data type capable of storing ONLY whole numbers.
- Has limitations, like not capable of storing numbers that
has decimals.

Example of Integer Data Type Program:

public class Integer{


public static void main(String[] args){

int ley=9;
int liah=5;
int lachi=1998;

System.out.println(ley);
System.out.println(liah);
System.out.println(lachi);

}
}
Character:

- The data type capable of storing Only a single letter,


regardless whether it is capitalized or not.

Example of Character Data Type Program:

public class Character{


public static void main(String[] args){

char ley='L';
char melca='i';
char lachi='a';
char alli='h';

System.out.println(ley);
System.out.println(melca);
System.out.println(lachi);
System.out.println(alli);
}
}
String:

- The data type that is capable of storing group of


characters to form a word.
- Very useful, depending on how you do it.

Example of String Data Type Program:

public class StringType{


public static void main(String[] args){

String lachi="Goddess";
String melca="Ley";

System.out.println("My Kind Of Perfect-" +lachi


+" " +melca);
}
}
Float:

- A data type capable of storing numbers in decimal but, is


more limited than of the double data type.
Note: A small f must be put after the inputted decimal number
or else it wont work out.
Example of Float Data Type Program:
public class Float{
public static void main(String[] args){

float melca=5;
float lachi=10.56f;

System.out.println(melca);
System.out.println(lachi);
}
}
Double:

- The data type which can be used for storing numbers with
decimal values.
- double data type is a double-precision 64-bit IEEE 754 floating
point

- This data type is generally used as the default data type for
decimal values, generally the default choice

- Double data type should never be used for precise values such
as currency

- Default value is 0.0d

Example of Double Data Type Program:

public class Double{

public static void main(String[] args){

double ley=98.2;
double lachi=97.60;
double liah=99.9;

System.out.println("The Chances are:" +" "+ ley +" "


+"accurate");

System.out.println("The Chances are:" +" "+ lachi +" "


+"accurate");

System.out.println("The Chances are:" +" "+ liah +" "


+"accurate");
}
}
Long:
- The data type used for storing very large quantity of
numbers.

- Is a 64-bit signed two's complement integer


- Minimum value is -9,223,372,036,854,775,808(-2^63)
- Maximum value is 9,223,372,036,854,775,807 (inclusive)
(2^63 -1)
- This type is used when a wider range than integer is needed
- Default value is 0L
- Example: long a = 100000L, long b = -200000L
Example of Long Data Type Program:

public class Long{


public static void main(String[] args){

long melca=330000;
long liah=9000000;

System.out.println(melca +" " +" is more than


100000");
System.out.println(liah +" " +" is more than
1000000");
}
}
Short:

-The data type capable of storing a small quantity of numbers.

-Short data type is a 16-bit signed two's complement integer

-Minimum value is -32,768 (-2^15)

-Maximum value is 32,767 (inclusive) (2^15 -1)

-Short data type can also be used to save memory as byte data type.
A short is 2 times smaller than an integer

-Default value is 0.

Example of Short Data Type Program:

public class Short{

public static void main(String[] args){

short lachi=30000;

System.out.println(lachi +" " +'>' +" " +"10000" );

}
Sample Scanner Program:

import java.util.Scanner;

public class DataTypes3{

public static void main(String[] args){

String liah;

String ley;

Scanner lachi=new Scanner(System.in);

System.out.println("Enter String:");

liah=lachi.next();

System.out.println("Enter String:");

ley=lachi.next();

System.out.println(liah +" " +ley);

}
}
Sample of Arithmetic Operations:
public class ArithmeticOperations{
public static void main(String[] args){

String liah="<3";

for(int ley=1; ley<=14; ley+=1){

System.out.println("I" +liah +"Her SO MUCH!");

liah+="<3";

continue;
}
String alli="With her is Sanctuary";

System.out.println(alli);

double a=9;
double m=5;
double l=1997;
double al;
double aml;
double ac;
al=a*m;
aml=al*1997;
ac=aml/100;
System.out.println(ac +" " +"years is how long I want to
stay with her");

}
}

S-ar putea să vă placă și