0% found this document useful (1 vote)
358 views2 pages

15 Java Programs with Outputs

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 (1 vote)
358 views2 pages

15 Java Programs with Outputs

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
  • Print ASCII Value of a Character
  • Check Armstrong Number

15 Java Programs with Output

Check Armstrong Number


Code:
import [Link];

public class ArmstrongNumber {


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

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

while (original != 0) {
int remainder = original % 10;
result += [Link](remainder, digits);
original /= 10;
}

if (result == num) {
[Link](num + " is an Armstrong number");
} else {
[Link](num + " is not an Armstrong number");
}
}
}

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

Print ASCII Value of a Character


Code:
import [Link];

public class ASCIIValue {


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

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

15 Java Programs with Output
Check Armstrong Number
Code:
import java.util.Scanner;
public class ArmstrongNumber {
    public
}
Output:
Enter a character: A
ASCII value of A is 65

You might also like