variable vs constant in java
All Contributions
create simple calculater using java
Scanner input = new Scanner(System.in);
System.out.println("please enter first number:");
int num1=input.nextInt();
System.out.println("please enter second number:");
int num2=input.nextInt();
int summation_result=num1+num2;
int subtraction_result=num1-num2;
int multiplication_result=num1*num2;
int division_result=num1/num2;
int remainder_result=num1%num2;
System.out.println("the summation result is :" + summation_result);
System.out.println("the subtraction result is :"+subtraction_result);
System.out.println("the multiplication result is :"+multiplication_result);
System.out.println("the division result is :"+division_result);
System.out.println("the remainder is :"+remainder_result);
write java program to switch values between 2 variables, using a temporary third variable
int x=5;
int y=10;
System.out.println("x before is : "+x+" y before is : "+y);
int temp=x;
x=y;
y=temp;
System.out.println("x after is : "+x+" y after is : "+y);
write java program to calculate rectangle perimeter, program should prompts user to enter length and width, 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 length of rectangle:");
int length=input.nextInt();
System.out.println("please enter the width of rectangle:");
int width=input.nextInt();
int area=length*width;
System.out.println("the rectangle area is "+area);
int perimeter=(length+width)*2;
System.out.println("the rectangle perimeter is "+perimeter);
}
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 (6)
(Geometry: area of a hexagon) Write a program that prompts the user to enter the
side of a hexagon and displays its area.