Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
81 views

Fixed 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)
81 views

Fixed 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/ 3

Java Programs with Outputs

This document contains 15 Java programs along with their outputs. Each program is detailed on a

separate page for better readability. The programs cover various basic and intermediate concepts of

Java programming.
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