Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhilrajsingh/1b5c77b5f35ba7008fbe78e4519b3818 to your computer and use it in GitHub Desktop.
Save nikhilrajsingh/1b5c77b5f35ba7008fbe78e4519b3818 to your computer and use it in GitHub Desktop.
Task 2 - Create a program in Java to declare, initialize and use local variables of all the primitive data types in Java.
//created by Nikhil Raj Singh
//section K
//Task 2 - Create a program in Java to declare, initialize and use local variables of all the primitive data types in Java.
public class DataTypes {
byte Byte; short Short;int Int;long Long;float Float;double Double; char Character;boolean Boolean;
void integerType(){
Byte = 1;
Short = 12;
Int = -23;
Long = 2L;
}
void floatingPoint(){
Float = 3.14f;
Double = 2.4e100d;
}
void characterValue(){
Character = 'a';
}
void print() {
integerType();
System.out.println("byte Type=" + Byte);
System.out.println("short Type=" + Short);
System.out.println("int Type=" + Int);
System.out.println("long Type=" + Long);
floatingPoint();
System.out.println("float Type=" + Float);
System.out.println("double Type=" + Double);
characterValue();
System.out.println("char Type=" + Character);
System.out.println("boolean Type=" + Boolean);
}
}
class execute{
public static void main(String[] args) {
DataTypes run= new DataTypes();
run.print();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment