Contents: Click for quick access
226. Write a program in java to ask any string and count total no of vowels and consonants.227. Write a program in java to enter any 10 numbers and find the sum of odd numbers.228. Write a program to convert Nepalese currency into Indian currency.229. Write a program to convert Nepalese currency into Indian currency.230. Write a program to check whether the input number is divisible by 4 and 6 or not.231. Write a program to input monthly income in to compute annual tax to be paid. The tax rate is 15% if annual income is above Rs. 500000, otherwise tax rate is 10%.
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
226. Write a program in java to ask any string and count total no of vowels and consonants.
import java.util.Scanner;
class Count{
public static void main(String[] args) {
String str = "";
int vowels = 0;
int consonants = 0;
System.out.println("Enter string");
Scanner MyScanner = new Scanner(System.in);
str = MyScanner.nextLine();
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == \'a\' || str.charAt(i) == \'e\' || str.charAt(i) == \'i\' || str.charAt(i) == \'o\' || str.charAt(i) == \'u\') {
vowels = vowels + 1;
} else if (str.charAt(i) == \'A\' || str.charAt(i) == \'E\' || str.charAt(i) == \'I\' || str.charAt(i) == \'O\' || str.charAt(i) == \'U\') {
vowels = vowels + 1;
} else {
consonants = consonants + 1;
}
}
System.out.println("No. of vowels is " + vowels);
System.out.println("No. of consonants is " + consonants);
}
}
227. Write a program in java to enter any 10 numbers and find the sum of odd numbers.
import java.util.Scanner;
class OddNumber {
public static void main(String[] args) {
{
int i, OddSum = 0;
Scanner sc = new Scanner(System.in);
int [] a = new int[10];
for (i = 0; i < 10; i++)
{
System.out.println("Enter number");
a[i] = sc.nextInt();
}
for(i = 0; i < 10; i++)
{
if(a[i] % 2 != 0)
{
OddSum = OddSum + a[i];
}
}
System.out.println(" The Sum of Odd Numbers in this Array = " + OddSum);
}
}
}
228. Write a program to convert Nepalese currency into Indian currency.
class Currency {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount in Nepalese currency");
double amount = sc.nextDouble();
double rate = 0.01;
double indian = amount * rate;
System.out.println("The amount in Indian currency is " + indian);
}
}
229. Write a program to convert Nepalese currency into Indian currency.
class Currency {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount in Nepalese currency");
double amount = sc.nextDouble();
double rate = 0.01;
double indian = amount * rate;
System.out.println("The amount in Indian currency is " + indian);
}
}
230. Write a program to check whether the input number is divisible by 4 and 6 or not.
import java.util.Scanner;
class Number {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int num = sc.nextInt();
if (num % 4 == 0 &; &; num % 6 == 0) {
System.out.println("The number is divisible by 4 and 6");
} else {
System.out.println("The number is not divisible by 4 and 6");
}
}
}
231. Write a program to input monthly income in to compute annual tax to be paid. The tax rate is 15% if annual income is above Rs. 500000, otherwise tax rate is 10%.
import java.util.Scanner;
class AnnualTax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the monthly income");
double income = sc.nextDouble();
double tax = 0;
if (income > 500000) {
tax = income * 0.15;
} else {
tax = income * 0.10;
}
System.out.println("The annual tax is " + tax);
}
}