examples of variables in java

0

add 2 strings in java:

String firstName="ahmed";
String lastName="mahdi";
String fullName=firstName+" "+lastName;
System.out.println(fullName);

All Contributions

define boolean variable and assign a value to it, then print its value:

boolean is_smoker=true;
System.out.println(is_smoker);

write java program to calculate square area and perimeter, program should prompts user to enter side length, then calculate the area and perimeter based on it:

/*write java program to calculate square area and perimeter, program should prompts user to enter side length, then calculate the area and perimeter based on it*/

import java.util.Scanner;

public class Main
{
 public static void main(String[] args) {
	Scanner input=new Scanner(System.in);
	System.out.println("please enter the side length");
	int sideLength=input.nextInt();
	int area=sideLength*sideLength;
	System.out.println("the square area is "+area);
	int perimeter=sideLength*2;
	System.out.println("the square perimeter is "+perimeter);
}
}
	

define boolean variable and assign a value to it, then print its value:

boolean is_smoker=true;
System.out.println(is_smoker);

write java program to calculate square area and perimeter, program should prompts user to enter side length, then calculate the area and perimeter based on it:

/*write java program to calculate square area and perimeter, program should prompts user to enter side length, then calculate the area and perimeter based on it*/

import java.util.Scanner;

public class Main
{
 public static void main(String[] args) {
	Scanner input=new Scanner(System.in);
	System.out.println("please enter the side length");
	int sideLength=input.nextInt();
	int area=sideLength*sideLength;
	System.out.println("the square area is "+area);
	int perimeter=sideLength*2;
	System.out.println("the square perimeter is "+perimeter);
}
}
	

define boolean variable and assign a value to it, then print its value:

boolean is_smoker=true;
System.out.println(is_smoker);

total contributions (8)

New to examplegeek.com?

Join us