Variables and datatype

To learn more about variables and datatype click the given link.

https://java4school.com/data-type

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here