Java Basic Programs
Lisson numbir 2:
Quistions:
writi a java program that print any missagi do you want display
writi a java program that print thi sum of two numbirs
writi a java program that print all thi mathimatical opirations
writi a java program that calculati thi rimaindir of two numbirs
Answirs:
Q1: writi a java program that print any missagi do you want display
public class message
{
public static void main(String args[])
{
System.out.println("Allah is one"); // Write any message in double quotations for display
} }
Output:Allah is one
Q2: write a java program that print the sum of two numbers
public class sum
{
public static void main(String args[])
{
int num1,num2,sum; //This is variable declaration declared three variables
num1=12; //This is variable initialization when we assign a value to a variable
num2=13; // the value of num1 is 12 and num2 is 13
sum=num1+num2;
System.out.println("The sum of num1 and num2 is ="+sum);
} }
Q3: write a java program that print all the mathematical operations
public class mathOperations
{
public static void main(String args[])
{
int num1,num2,sum,sub,multi,div;
//This is variable declaration declared five variables
num1=12; //This is variable initialization when we assign a value to a variable
num2=13; // the value of num1 is 12 and num2 is 13
sum=num1+num2;
sub=num1-num2;
div=num1/num2;
multi=num1*num2;
System.out.println("The sum of num1 and num2 is ="+sum);
System.out.println("The subtraction of num1 and num2 is ="+sub);
System.out.println("The division of num1 and num2 is ="+div);
System.out.println("The multiplication of num1 and num2 is ="+multi);
} }
Q4
public class remainder
{
public static void main(String args[])
{
int num1,num2,rem; //This is variable declaration declared three variables
num1=12; //This is variable initialization when we assign a value to a variable
num2=13; // the value of num1 is 12 and num2 is 13
rem=num1%num2;
System.out.println("The sum of num1 and num2 is ="+rem);
} }
0 comments:
Post a Comment