this site is to help students to learn coding in java platform and qbasic platform. all programs are ICSE and ISC level. Java programs java python Python programs
Kaprekar Number
This program checks whether a number is Kaprekar number or not.
A number is said to be Kaprekar number if its sum of digits in its square is the number itself.
Example- 9^2 is 81 and 8+1 is 9.So it is a Kaprekar number.
import java.util.*;
public class KaprekarNumbers
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter number");
int n=ob.nextInt();
int N=n*n;
int tn=n;int c=0;
while(tn!=0)
{
tn=tn/10;c++;
}
int q=(int)(N/Math.pow(10,c));
int r=(int)(N%Math.pow(10,c));
if(q+r==n)
System.out.println("Kaprekar number");
else
System.out.println("Non Kaprekar number");
A number is said to be Kaprekar number if its sum of digits in its square is the number itself.
Example- 9^2 is 81 and 8+1 is 9.So it is a Kaprekar number.
import java.util.*;
public class KaprekarNumbers
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter number");
int n=ob.nextInt();
int N=n*n;
int tn=n;int c=0;
while(tn!=0)
{
tn=tn/10;c++;
}
int q=(int)(N/Math.pow(10,c));
int r=(int)(N%Math.pow(10,c));
if(q+r==n)
System.out.println("Kaprekar number");
else
System.out.println("Non Kaprekar number");
}
}
Calculating and printing the nth prime number
Calculating and printing the nth prime number
Question:
How to write a java program Given a number n as input, return the value of the nth prime. Note that n is always greater than 0.?
Code:
import java.util.Scanner; public class NthPrime { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter n to compute the nth prime number: "); int nth = sc.nextInt(); int num, count, i; num=1; count=0; while (count < nth){ num=num+1; for (i = 2; i <= num; i++){ if (num % i == 0) { break; } } if ( i == num){ count = count+1; } } System.out.println("Value of nth prime: " + num); } }
Output:
$ java NthPrime Enter n to compute the nth prime number: 10 Value of nth prime: 29
Subscribe to:
Comments (Atom)
Infix postfix prefix
import java.util.Stack; import java.util.Scanner; public class ExpressionConverter { // Function to return precedence of operators ...
-
Chapter 3 Arrays Class 10 - APC Understanding Computer Applications with BlueJ Tick the correct answer Question 1 Which of the following i...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...
-
/* Write a program to accept a number and check it is a lead number or not. Lead number is a number in which the sum of the even digits is...







