Java Variables

Java Variables:

 

  • There are five types of variables in java they are:
  • String: it stores name in double quotes
  • Int: stores integral numbers and non-decimal numbers.
  • float: stores decimal floating digits.
  • Char: stores single characters in single quotes.
  • Boolean: Evaluates a given condition.

String:

public class Main
{
public static void main(String[] args) {
String name = "Prequelcoding";
System.out.println(name);
}
}

Int:
public class Main
{
public static void main(String[] args) {
int myNum = 4;
System.out.println(myNum);
}
}
Adding two integers:
public class Main
{
public static void main(String[] args) {
int myNum = 4;
int myNum2 = 10;
System.out.println(myNum + myNum2);
}
}

Multiplying Two Integers:

public class Main
{
public static void main(String[] args) {
int myNum = 4;
int myNum2 = 10;
System.out.println(myNum * myNum2);
}
}
Subtracting Two Integers:
public class Main
{
public static void main(String[] args) {
int myNum = 4;
int myNum2 = 10;
System.out.println(myNum2 - myNum);
}
}

Dividing Two Integers:
public class Main
{
public static void main(String[] args) {
int myNum = 9;
int myNum2 = 72;
System.out.println(myNum2 /myNum);
}
}
Char implementation:
public class Main
{
public static void main(String[] args) {
char name = 'P';
System.out.println(name);
}
}







Scroll to top