A simple program to use variable & Datatype
https://wordpress-343193-1101484.cloudwaysapps.com/data-type
To learn more about variables and datatype click the given link.
Write a program to declare and initialize some variables of int, string and double , accept their values and print the result according the requirement.
public class Variables
{
public static void main()
{
//declaration of variables
String st_nm;
int std;
double total;
int roll_no;
int math;
int geo;
int comp;
int bio;
int hin;
//initialization of variables with the values
st_nm="Dhvani";
std=12;
roll_no=1201;
math=98;
geo=100;
comp=99;
bio=97;
hin=90;
total=math+geo+comp+bio+hin;
System.out.println("The total marks of”+ st_nm+” is "+total);
double average=total/5;
System.out.println("The average of ”+ st_nm +” is "+average);
double per=total*100/500;
System.out.println("The percentage of”+ st_nm +” is "+per);
}
}Output:
The total marks of Dhvani is 484.0
The average of Dhvani is 96.8
The percentage of Dhvani is 96.8
To learn more about taking input using scanner class watch the video
https://youtu.be/GeSDLXhzFig
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.