The document contains Java code snippets for various number-related programs, including checking for co-prime numbers, Duck numbers, Buzz numbers, Dudeney numbers, and Prime numbers. It demonstrates user input handling, conditional statements, and loops to perform calculations and validations. The code also includes sample inputs and outputs for better understanding of the functionality.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views2 pages
Co Prime Scanner in
The document contains Java code snippets for various number-related programs, including checking for co-prime numbers, Duck numbers, Buzz numbers, Dudeney numbers, and Prime numbers. It demonstrates user input handling, conditional statements, and loops to perform calculations and validations. The code also includes sample inputs and outputs for better understanding of the functionality.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Co prime Scanner in = new Scanner(System.in); System.out.
println(n + " is not a
System.out.print("Enter a: "); Dudeney number"); int a = in.nextInt(); } System.out.print("Enter b: "); int b = in.nextInt; int hcf = 1; for (int i = 1; i <= a && i <= b; i++) { (30 + 25)2 (55)2= 3025 is a tech number. if (a % i == 0 && b % i == 0) for (int i = 1000; i <= 9999; i++) { hcf = i; } int secondHalf = i % 100; if (hcf == 1) int firstHalf = i / 100; System.out.println(a + " and " + b + int sum = firstHalf + secondHalf; " are co-prime"); if (i == sum * sum) else System.out.println(i) } System.out.println(a + " and " + b + " are not co-prime"); Sample Input: 45, 20 Sample Output: GCD=5 } Scanner in = new Scanner(System.in); Duck no. Scanner sc = new Scanner(System.in); System.out.print("Enter first number: System.out.print("Input a number : ") String nstr "); = sc.nextLine(); int a = in.nextInt(); int l = nstr.length(); System.out.print("Enter second number: int ctr = 0; "); char chr; int b = in.nextInt(); for(int i=1;i<l;i++) while (b != 0) { { int t = b; chr = nstr.charAt(i); b = a % b; if(chr=='0') a = t; ctr++; } } System.out.println("GCD=" + a); char f = nstr.charAt(0); Write a menu driven program to accept a number from the user and check whether it is a Prime if(ctr>0 && f!='0') number or an Automorphic number. System.out.println("Duck number"); Scanner in = new Scanner(System.in); else System.out.println("1. Prime number"); System.out.println("Not a duck System.out.println("2. Automorphic number"); number"); } Buzz no. Scanner in = new System.out.print("Enter your choice: "); Scanner(System.in); int choice = in.nextInt(); System.out.print("Enter p: "); System.out.print("Enter number: "); int p = in.nextInt(); int num = in.nextInt(); System.out.print("Enter q: "); int q = in.nextInt(); switch (choice) { if (p < q) { case 1: System.out.println("Buzz Numbers int c = 0; between " for (int i = 1; i <= num; i++) { + p + " and " + q); if (num % i == 0) { for (int i = p; i <= q; i++) { c++; if (i % 10 == 7 || i % 7 == 0) } System.out.println(i); } } } if (c == 2) else { System.out.println(num + " is System.out.println("Invalid Prime"); Inputs!!!"); else System.out.println("p should be less System.out.println(num + " is than q"); not Prime"); } break; Dudeney number. Scanner in = new Scanner(System.in); case 2: System.out.print("Enter the number: "); int numCopy = num; int n = in.nextInt(); int sq = num * num; int d = 0; //Check if n is a perfect cube int cubeRoot /* =(int)Math.round(Math.cbrt(n)); * Count the number of if (cubeRoot * cubeRoot * cubeRoot == n) * digits in num { */ //If n is perfect cube then find while(num > 0) { //sum of its digits d++; int s = 0; num /= 10; int t = n; } while (t != 0) { int d = t % 10; /* s += d; * Extract the last d digits t /= 10; * from square of num } */ int ld = (int)(sq % Math.pow(10, if (s == cubeRoot) { d)); System.out.println(n + " is a Dudeney number"); if (ld == numCopy) } System.out.println(numCopy + " else { is automorphic"); System.out.println(n + " is not else a Dudeney number"); System.out.println(numCopy + " } is not automorphic"); } break; else { default: System.out.println("Incorrect Choice"); break;