Contents: Click for quick access
216. Write a program in java TO ENTER ANY DIGIT AND PRINT CUBE OF EVEN DIGITS.217. Write a program to enter any 10 numbers and display the greatest one.218. Write a program in java TO ENTER ANY DIGIT AND PRINT SQUARE OF ODD.219. Write a program in java to generate the following series 54321,5432,543,54,5.220. Write a program to enter any 20 numbers and display the smallest one using.221. Write a program to solve a quadratic equation ax2+bx+c=0 on the basis of the coefficient values a, b, and c.222. Write a program in java to print -30,-20,-10,0,10,……………20th terms.223. Write a program in java to ask any string and print only consonant by removing vowels.224. Write a program in java to ask number and count total number of digits.225. Write a program in java to find the sum of all even numbers from 2 to 100.
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
216. Write a program in java TO ENTER ANY DIGIT AND PRINT CUBE OF EVEN DIGITS.
import java.util.Scanner;
class CubeOfEvenDigit {
public static void main(String args[])
{
Scanner scanner= new Scanner(System.in);
System.out.println("Enter any number");
int n= scanner.nextInt();
int sum = 0;
for(int i = 1; i <= n; i++)
sum += (2 * i) * (2 * i)
* (2 * i);
System.out.println(sum);
}
}
217. Write a program to enter any 10 numbers and display the greatest one.
import java.util.Scanner;
class GreatestNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your 10 numbers");
int[] num = new int[10];
for (int i = 0; i < 10; i++) {
num[i] = sc.nextInt();
}
int max = num[0];
for (int i = 0; i < 10; i++) {
if (num[i] > max) {
max = num[i];
}
}
System.out.println("The greatest number is " + max);
}
}
218. Write a program in java TO ENTER ANY DIGIT AND PRINT SQUARE OF ODD.
import java.util.Scanner;
class SquareOfOddDigits {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter any number");
int n = scanner.nextInt();
System.out.println("SQUARE OF ODD DIGITS ARE");
while(n!=0){
int r= n%10;
if (r%2==1){
System.out.println(r*r);
n= n/10;
}
}
}
}
219. Write a program in java to generate the following series 54321,5432,543,54,5.
class Series {
public static void main(String[] args) {
int n = 54321;
while(n!=0){
System.out.print(n+" ");
n=n/10;
}
}
}
220. Write a program to enter any 20 numbers and display the smallest one using.
class SmallestNumber {
public static void main(String args[]){
int a[]={1,2,5,6,3,2};
int temp;
int total =6;
for (int i = 0; i < total; i++)
{
for (int j = i + 1; j < total; j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.println(a[0]);
}}
221. Write a program to solve a quadratic equation ax2+bx+c=0 on the basis of the coefficient values a, b, and c.
import java.util.Scanner;
class Equation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a, b, and c");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
double d = Math.pow(b, 2) - 4 * a * c;
if (d < 0) {
System.out.println("The equation has no real roots");
} else if (d == 0) {
double x = -b / (2 * a);
System.out.println("The equation has one real root " + x);
} else {
double x1 = (-b + Math.sqrt(d)) / (2 * a);
double x2 = (-b - Math.sqrt(d)) / (2 * a);
System.out.println("The equation has two real roots " + x1 + " and " + x2);
}
}
}
222. Write a program in java to print -30,-20,-10,0,10,……………20th terms.
class Series {
public static void main(String args[]) {
int a = -30;
for (int i = 0; i < 20; i++) {
System.out.println(a);
a = a + 10;
}
}
}
223. Write a program in java to ask any string and print only consonant by removing vowels.
import java.util.Scanner;
class Vowels {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a String : ");
String str = scanner.next();
int count = 0;
String word = "";
for (int i = 0; i < str.length(); i++) {
char character =str.charAt(i);
if(character==\'a\' || character==\'A\' || character==\'e\'|| character==\'E\' ||
character==\'i\' || character==\'I\' || character==\'o\' || character==\'O\' ||
character==\'u\' || character==\'U\'){
}
else{
word=word+character;
}
}
System.out.println(word);
}
}
224. Write a program in java to ask number and count total number of digits.
import java.util.Scanner;
class TotalNumberDigit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter any number");
int num = sc.nextInt();
int count = 0;
while (num != 0) {
num = num / 10;
count++;
}
System.out.println("The total number of digits is " + count);
}
}
225. Write a program in java to find the sum of all even numbers from 2 to 100.
import java.util.Scanner;
class Series {
public static void main(String[] args) {
for (int i = 2; i < 100; i=i+2) {
System.out.print(i+ " ");
}
}
}