0% found this document useful (0 votes)
385 views2 pages

15 Java Programs With Output

Uploaded by

abhiieku07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
385 views2 pages

15 Java Programs With Output

Uploaded by

abhiieku07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

15 Java Programs with Output

Check Armstrong Number


Code:
import java.util.Scanner;

public class ArmstrongNumber {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
int original = num, result = 0, digits = 0;

while (original != 0) {
original /= 10;
digits++;
}
original = num;

while (original != 0) {
int remainder = original % 10;
result += Math.pow(remainder, digits);
original /= 10;
}

if (result == num) {
System.out.println(num + " is an Armstrong number");
} else {
System.out.println(num + " is not an Armstrong number");
}
}
}

Output:
Enter a number: 153
153 is an Armstrong number

Print ASCII Value of a Character


Code:
import java.util.Scanner;

public class ASCIIValue {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = sc.next().charAt(0);
int asciiValue = (int) ch;
System.out.println("ASCII value of " + ch + " is " + asciiValue);
}
}

Output:
Enter a character: A
ASCII value of A is 65

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy