examples of variables in java
All Contributions
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);
}
}
total contributions (8)
define boolean variable and assign a value to it, then print its value: