Contents: Click for quick access
166. Write the program in Java to display the first ten terms of the following series: 1, 12, 123, 1234.167. Write a program in java to print Armstrong numbers from 0 t0 1000.168. Write a program in java to ask string and find whether the first character is a number or uppercase or lowercase.169. Write a program in java to count the frequency of characters R or S present in the supplied string.170. Write a program in java to generate the following series 123456789,1234567,12345,123,1.171. Write a program in java to print cube of an ask number.172. WRITE A PROGRAM IN java to ask number and find sum of digits.173. Write a program to input any number and check whether the given no. is divisible by 3 and 7 or not.174. Write a program in java to ask any string and count total no. of sentences.175. Write a program in java to generate the following series 2,4,6,8…………12th term.
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
166. Write the program in Java to display the first ten terms of the following series: 1, 12, 123, 1234.
class Series {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j);
}
System.out.print(", ");
}
}
}
167. Write a program in java to print Armstrong numbers from 0 t0 1000.
class ArmstrongNumber {
public static void main(String[] args) {
int temp, digit, digitCubeSum;
for (int i = 0; i <1000; i++) {
temp = i;
digitCubeSum = 0;
while (temp != 0) {
digit = temp % 10;
digitCubeSum = digitCubeSum + digit * digit * digit;
temp /= 10;
}
if (digitCubeSum == i)
System.out.println(i);
}
}
}
168. Write a program in java to ask string and find whether the first character is a number or uppercase or lowercase.
import java.util.Scanner;
class FindCharacter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your string");
String str = sc.nextLine();
char ch = str.charAt(0);
if (Character.isDigit(ch)) {
System.out.println("First character is a number");
} else if (Character.isUpperCase(ch)) {
System.out.println("First character is a uppercase");
} else if (Character.isLowerCase(ch)) {
System.out.println("First character is a lowercase");
} else {
System.out.println("First character is a special character");
}
}
}
169. Write a program in java to count the frequency of characters R or S present in the supplied string.
import java.util.Scanner;
class Frequency {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your string");
String str = sc.nextLine();
int count = 0;
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch == \'R\' || ch == \'S\') {
count++;
}
}
System.out.println("The frequency of R or S is " + count);
}
}
170. Write a program in java to generate the following series 123456789,1234567,12345,123,1.
class Series {
public static void main(String[] args) {
int i, j;
for (i = 7; i >= 1; i -= 2) {
for (j = 1; j <= i; j++) {
System.out.print(j);
}
System.out.print(" ");
}
}
}
171. Write a program in java to print cube of an ask number.
import java.util.Scanner;
class Cube {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a number");
int x = scanner.nextInt();
int cube= x*x*x;
System.out.println(cube);
}
}
172. WRITE A PROGRAM IN java to ask number and find sum of digits.
import java.util.Scanner;
class SumOfDigits
{
public static void main(String args[])
{
int number, digit, sum = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
number = sc.nextInt();
while(number > 0)
{
digit = number % 10;
sum = sum + digit;
number = number / 10;
}
System.out.println("Sum of Digits: "+sum);
}
}
173. Write a program to input any number and check whether the given no. is divisible by 3 and 7 or not.
import java.util.Scanner;
class Divisible {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your number");
int num = sc.nextInt();
if (num % 3 == 0 &; &; num % 7 == 0) {
System.out.println("The number is divisible by 3 and 7");
} else {
System.out.println("The number is not divisible by 3 and 7");
}
}
}
174. Write a program in java to ask any string and count total no. of sentences.
import java.util.Scanner;
class Sentences {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your string");
String str = sc.nextLine();
int count = 0;
for (int i = 0; i <str.length(); i++) {
char ch = str.charAt(i);
if (ch == \'.\' || ch == \'!\' || ch == \'?\') {
count++;
}
}
System.out.println("The total no. of sentences is " + count);
}
}
175. Write a program in java to generate the following series 2,4,6,8…………12th term.
import java.util.Scanner;
class SumOfDigits
{
public static void main(String args[])
{
int a = 2;
for (int i = 1; i <12 ; i++) {
System.out.print(a+ " ");
a=a+2;
}
}
}