How to find the Area of the cube using Scanner class

Share Your Love

Hello guys, welcome to Lingarajtechhub. Today we are going to discuss finding the Area of the cube using Scanner class.

Code:

package com.Arithmatic_operator.java;
//it is a java package( com.Arithmatic_operator.java) which is collection of classes and this package is created in java project.


import java.util.Scanner;
//Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings

public class Area_of_cube {
	 //Here   Area_of_cube is defined as a class which  is a template used to create objects and to define object data types and methods .
    //and its define as public because it access any where .
  
	public static void main(String[] args) {
			// it is a main method in which we can execute a program
			//public :it is a access modifier of the main function  which is must be  public so that the JRE which is (Java Run Time Environment)can access and execute this method. 
			//If a method is not  public, then access is restricted and its showing error
			//static is a keyword in which main method has must to be static in which JVM can load the class into memory and call the main method without creating an instance 
			//void  it means no return type
			//main() is function
							/*
					string[]args  : string means collection of charecters ,String[] args represents a collection of Strings
							that are separated by a space and can be typed into the program on the terminal directly
							*/
		double area,side;
		//Here we Declare 2 variable area ,side which is double type 
		Scanner sc=new Scanner(System.in);
		//here scanner is a class and Sc is the instance of the object which is  new Scanner.System.in is an argument
		System.out.println("Enter the sides of cube");
		//it means System is a class name and out is an instance of the System println is print a new line
		side=sc.nextDouble();
		//here side is a variable that we take and sc is our instance name which is create for  a object and nextDouble() is a method method of a Scanner object reads in a string of digits or char  and converts them into a double  type
		area=6*(side*side);
		//here we apply the logic ,for find the area of a cube ,we use the formula 6*square of sides then we assign "6*(side*side)" this value to area ,then we find the value of area
		System.out.println("area of a cube "+area);
		//it means System is a class name and out is an instance of the System println is print a new line
	   //+area ,+ means cocardinate act like as a comma operator,and here area means 6*(side*side)  expression result is assign to area variable then result is shown

		
	}

}

Line 1:

package com.Arithmatic_operator.java;

–> it is a java package( com.Arithmatic_operator.java) which is collection of classes and this package is created in java project.

Line 2:

import java.util.Scanner;

–> Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings

Line 8:

public class Area_of_cube {
//Here Area_of_cube is defined as a class which is a template used to create objects and to define object data types and methods .
//and its define as public because it access any where .

Line 12:

public static void main(String[] args) {
// it is a main method in which we can execute a program
//public :it is a access modifier of the main function which is must be public so that the JRE which is (Java Run Time Environment)can access and execute this method.
//If a method is not public, then access is restricted and its showing error
//static is a keyword in which main method has must to be static in which JVM can load the class into memory and call the main method without creating an instance
//void it means no return type
//main() is function
/*
string[]args : string means collection of charecters ,String[] args represents a collection of Strings
that are separated by a space and can be typed into the program on the terminal directly
*/

Line 23:

double area,side;
//Here we Declare 2 variable area ,side which is double type

Line 25:

Scanner sc=new Scanner(System.in);
//here scanner is a class and Sc is the instance of the object which is new Scanner.System.in is an argument

Line 27:

System.out.println(“Enter the sides of cube”);
//it means System is a class name and out is an instance of the System println is print a new line

Line 29:

side=sc.nextDouble();
//here side is a variable that we take and sc is our instance name which is created for an object and nextDouble() is a method of a //Scanner //object that reads a string of digits or char and converts them into a double type

Line 31:

area=6(side side);
//here we apply the logic, for find the area of a cube, we use the formula 6square of sides then we assign “6(side*side)” this value to the area then //we find the value of an area

Line 33:

System.out.println(“area of a cube “+area);
//it means System is a class name and out is an instance of the System println is print a new line
//+area,+ means coordinate act like as a comma operator, and here area means 6(side-side) expression result is assigned to area variable then //result is shown

Share Your Love
Avatar photo
SONALIN SAHOO

Myself Sonalin Shaoo. I am quite happy to contribute here some java programming content and my friends Lipsa Mohanty ,Sushil Puhan, Aswin Kumar Nayak also help me to contribute their Opinion on this .

Articles: 40

Newsletter Updates

Enter your email address below to subscribe to our newsletter