Contents: Click for quick access
77. Write a program in java to ask three sides of a triangle and determine whether a triangle can be formed or not.78. Write a program in java to ask three sides of a triangle and determine whether a triangle is equilateral isosceles or scalene triangle or not.79. Write a program in java to generate the series 10,20,30………100.80. Write a program to input any number and display whether it is odd or even.81. Write a program to input any number and check whether the given no. is divisible by 5 or not.82. Write a program in java to enter any 15 numbers and print only those numbers which are divisible by 5.83. Write a program in java to generate the following series 3, 6, 12, 24, 48, ….. to n.84. Write a program in java to ask number and count total number of odd digits.85. Write a program in java to print square root of an ask number.86. Write a program in java to enter any ten strings and print the shortest string.
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
77. Write a program in java to ask three sides of a triangle and determine whether a triangle can be formed or not.
class Triangle {
public static void main(String[] args) {
int side1 = 0;
int side2 = 0;
int side3 = 0;
System.out.println("Enter three sides of a triangle: ");
side1 = Integer.parseInt(System.console().readLine());
side2 = Integer.parseInt(System.console().readLine());
side3 = Integer.parseInt(System.console().readLine());
if (side1 + side2 > side3 && side2 + side3 > side1 && side1 + side3 > side2) {
System.out.println("Triangle can be formed");
} else {
System.out.println("Triangle cannot be formed");
}
}
}
78. Write a program in java to ask three sides of a triangle and determine whether a triangle is equilateral isosceles or scalene triangle or not.
class Triangle {
public static void main(String[] args) {
int side1 = 0;
int side2 = 0;
int side3 = 0;
System.out.println("Enter three sides of a triangle: ");
side1 = Integer.parseInt(System.console().readLine());
side2 = Integer.parseInt(System.console().readLine());
side3 = Integer.parseInt(System.console().readLine());
if (side1 == side2 && side2 == side3) {
System.out.println("Triangle is equilateral");
} else if (side1 == side2 || side2 == side3 || side1 == side3) {
System.out.println("Triangle is isosceles");
} else {
System.out.println("Triangle is scalene");
}
}
}
79. Write a program in java to generate the series 10,20,30………100.
class Series
{
public static void main(String args[]) {
int a=10;
for (int i = 1; i <= 10; i++) {
System.out.print(a+ " ");
a=a+10;
}
}
}
80. Write a program to input any number and display whether it is odd or even.
class OddEven {
public static void main(String[] args) {
int num = 0;
System.out.println("Enter a number: ");
num = Integer.parseInt(System.console().readLine());
if (num % 2 == 0) {
System.out.println("Number is even");
}
else {
System.out.println("Number is odd");
}
}
}
81. Write a program to input any number and check whether the given no. is divisible by 5 or not.
class Divisible {
public static void main(String[] args) {
int num = 0;
System.out.println("Enter a number: ");
num = Integer.parseInt(System.console().readLine());
if (num % 5 == 0) {
System.out.println("Number is divisible by 5");
} else {
System.out.println("Number is not divisible by 5");
}
}
}
82. Write a program in java to enter any 15 numbers and print only those numbers which are divisible by 5.
class Divisible {
public static void main(String[] args) {
int num = 0;
int count = 0;
int divisibleBy5 = 0;
System.out.println("Enter 15 numbers: ");
for (int i = 0; i < 15; i++) {
num = Integer.parseInt(System.console().readLine());
if (num % 5 == 0) {
divisibleBy5 = divisibleBy5 + num;
count++;
}
}
System.out.println("Total number of numbers divisible by 5 is: " + count);
System.out.println("Sum of numbers divisible by 5 is: " + divisibleBy5);
}
}
83. Write a program in java to generate the following series 3, 6, 12, 24, 48, ….. to n.
import java.util.Scanner;
class Series
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter n: ");
int n = in.nextInt();
int t = 3;
for (int i = 1; i <= n; i++) {
System.out.print(t + " ");
t *= 2;
}
}
}
84. Write a program in java to ask number and count total number of odd digits.
class OddDigit {
public static void main(String[] args) {
int num = 0;
int count = 0;
System.out.println("Enter a number: ");
num = Integer.parseInt(System.console().readLine());
while (num != 0) {
if (num % 2 != 0) {
count++;
}
num = num / 10;
}
System.out.println("Total number of odd digits is: " + count);
}
}
85. Write a program in java to print square root of an ask number.
class SquareRoot {
public static void main(String[] args) {
int num = 0;
System.out.println("Enter a number: ");
num = Integer.parseInt(System.console().readLine());
double sqrt = Math.sqrt(num);
System.out.println("Square root of " + num + " is: " + sqrt);
}
}
86. Write a program in java to enter any ten strings and print the shortest string.
class Smallest
{
public static String smallest(String words[]) {
if (words == null || words.length < 1) {
return "";
}
String smallest = words[0];
for (int i = 1; i < words.length; i++) {
if (words[i].length() < smallest.length()) {
smallest = words[i];
}
}
return smallest;
}// smallest
public static void main(String[] args) {
String[] SA = { "hello", "goodbye", "jack", "bye", "yes", "no", "yoo" };
System.out.println("The shortest word is " + smallest(SA));
}
}