Contents: Click for quick access
87.Write a program to enter any two numbers and display the greater one.88. Write a program in java to enter any 15 numbers and print only those numbers which are divisible by 5 and 7.90. Write a program in java to generate the following series 1,23,456,78910.91. Write a program in java to ask number and check whether the given no is prime or composite.92. Write a program in java to convert binary number to decimal number.93. Write a program in java to ask any number and check whether the given number is Armstrong or not.94. Write a program in java to print first ten multiples of ask number.95. Write a program in java to ask three sides of a triangle and determine whether a triangle is right angled triangle or not.
I’ve included a list of some of the Java programs below. You may also view all of the Java programs on our mobile app. I strongly advise you to use our mobile app for a better experience.
Please click the link to get our app–> https://play.google.com/store/apps/details?id=com.allbachelor.javaapp&hl=en&gl=US
87.Write a program to enter any two numbers and display the greater one.
import java.util.Scanner;
class Greater
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter First number");
int a= sc.nextInt();
System.out.println("Enter Second number");
int b = sc.nextInt();
if(a> b){
System.out.println(a+"is greater");
}
else{
System.out.println(b+ "is greater");
}
}
}
88. Write a program in java to enter any 15 numbers and print only those numbers which are divisible by 5 and 7.
import java.util.*;
class Divisible{
public static void main(String[] args) {
int[] num = new int[15];
for (int i = 0; i < num.length; i++) {
System.out.println("Enter number " + (i + 1));
Scanner MyScanner = new Scanner(System.in);
num[i] = MyScanner.nextInt();
}
for (int i = 0; i < num.length; i++) {
if (num[i] % 5 == 0 & & num[i] % 7 == 0) {
System.out.println(num[i]);
}
}
}
}
90. Write a program in java to generate the following series 1,23,456,78910.
import java.util.Scanner;
class Pattern{
public static void main(String[] args) {
int k=1;
for(int r=1;r <=4;r++)
{
for(int c=1;c <=r;c++)
{
System.out.print(k);
k++;
}
System.out.print(" ");
}
}
}
91. Write a program in java to ask number and check whether the given no is prime or composite.
class PrimeAndComposite{
public static void main(String[] args) {
int num = 0;
System.out.println("Enter number");
Scanner MyScanner = new Scanner(System.in);
num = MyScanner.nextInt();
int count = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
count++;
}
}
if (count == 2) {
System.out.println("Number is prime");
} else {
System.out.println("Number is composite");
}
}
}
92. Write a program in java to convert binary number to decimal number.
class BinaryToDecimal{
public static void main(String[] args) {
int num = 0;
System.out.println("Enter binary number");
Scanner MyScanner = new Scanner(System.in);
num = MyScanner.nextInt();
int dec = 0;
int i = 0;
while (num != 0) {
int rem = num % 10;
dec = (int) (dec + rem * Math.pow(2, i));
i++;
num = num / 10;
}
System.out.println("Decimal number is " + dec);
}
}
93. Write a program in java to ask any number and check whether the given number is Armstrong or not.
class Armstrong{
public static void main(String[] args) {
int num = 0;
System.out.println("Enter number");
Scanner MyScanner = new Scanner(System.in);
num = MyScanner.nextInt();
int sum = 0;
int temp = num;
while (num != 0) {
int rem = num % 10;
sum = sum + (rem * rem * rem);
num = num / 10;
}
if (temp == sum) {
System.out.println("Number is Armstrong");
} else {
System.out.println("Number is not Armstrong");
}
}
}
94. Write a program in java to print first ten multiples of ask number.
import java.util.*;
class Multiples{
public static void main(String[] args) {
int num = 0;
System.out.println("Enter number");
Scanner MyScanner = new Scanner(System.in);
num = MyScanner.nextInt();
for (int i = 1; i <= 10; i++) {
System.out.println(num * i);
}
}
}
95. Write a program in java to ask three sides of a triangle and determine whether a triangle is right angled triangle or not.
import java.util.*;
class Triangle{
public static void main(String[] args) {
int a = 0;
int b = 0;
int c = 0;
System.out.println("Enter first side");
Scanner MyScanner = new Scanner(System.in);
a = MyScanner.nextInt();
System.out.println("Enter second side");
b = MyScanner.nextInt();
System.out.println("Enter third side");
c = MyScanner.nextInt();
if (a * a + b * b == c * c) {
System.out.println("Triangle is right angled");
} else {
System.out.println("Triangle is not right angled");
}
}
}