PhysicsTeacher.in

High School Physics

Java program

Java Program for prime number checking

Let’s see how to write a Java program to accept a number and check whether the number is a Prime number or not. A prime number is a whole number greater than 1 whose only factors are 1 and itself. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, […]

Java program to find HCF (highest common factor) of 2 numbers

Let’s see how to write a Java program to find the HCF (highest common factor) of 2 numbers. Here is a Java program that accepts 2 numbers and finds the greatest common divisor or HCF (highest common factor) of those numbers. Java Program to find HCF import java.util.Scanner;public class HCF { public static void main(String […]

Write a Java program to find the factorial of a given number (using loop)

Let’s see how to write a Java program to find the factorial of a given number (using loop). Java program to find factorial class Factorial{ public static void main(String args[]){int i; long fact=1;int number=10;//It is the number whose factorial is calculated, modify it if needed for(i=1;i<=number;i++){fact=fact*i;System.out.println(“printing from inside loop:”+fact);} System.out.println(“Factorial of “+number+” is: “+fact);}}

Palindrome Program in Java using String methods

Here is a Java program that is written as a Palindrome Program in Java using String methods. This program allows the user to enter a string/number. Then the program checks whether the input is a Palindrome or not, and then responds back accordingly. This program is useful for students who are learning Java (or BlueJ). […]

Scroll to top
error: physicsTeacher.in