How to Create a Java Program for Division. (With explanations)
Java is a common Programming Language used nowadays. In this blog, I will show you how to create a simple Java Program for Division.
Java is easy to understand.
Java may look difficult but is very easy. If you are having problems in learning it, I have created a tutorial below on how to learn it. Believe me, it is very easy.
1.While writing a division program, you must start with
import java.util.*;
Note: don't forget to write ";". It acts as a full stop.
2.Now you need to write "class" and the name of your program.
3.After that, you have to write a command. It is "public static void main()"
4. Next write the scanner class. Just write "Scanner x= new Scanner (System.in);"
5. Next, write "int" and any character such as a,b and c. Int means integer.
6. Now you have to write the output which will be visible to the visitor. So if my characters are a,b,c then- System.out.println("Please enter the value of a");
a=x.nextInt();
System.out.println("Please enter the value of b");
b=x.nextInt();
c=a/b;
System.out.println("The answer is " +c);
}
}
And your program is complete!
This is how your program will look like-
import java.util.*;
class Division
{
public static void main()
{
Scanner x= new Scanner (System.in);
int a,b,c;
System.out.println("Please enter the value of a");
a=x.nextInt();
System.out.println("Please enter the value of b");
b=x.nextInt();
c=a/b;
System.out.println("The answer is " +c);
}
}
If you read the explainations carefully and practice it daily, then you will be able to program with Java easily.
If you want to create a program for addition, you just need to replace the / with +. You can do this also for subtraction and multiplication.
That's all for today. I hope you liked my blog. If you liked it, then do share it. Also, Don't forget to follow my blog.
Thank You
Read more
How did the Deadliest Pandemics in History end?
Comments
Post a Comment