import java.util.Scanner;
public class Program_8 {
public static void main(String[] args) {
System.out.println("Enter the word 'quit' to end this program.");
String str;
int x = 0, A = 0, E = 0, I = 0, O = 0, U = 0;
char ch;
Scanner in = new Scanner(System.in);
while (x < 1) {
str = in.next();
if (str.equals("quit")) {
x++;
in.close();
break;
} else {
for (int i = 0; i < str.length(); i++) {
ch = str.charAt(i);
if (ch == 'a' || ch == 'A') {
A++;
} else if (ch == 'e' || ch == 'E') {
E++;
} else if (ch == 'i' || ch == 'I') {
I++;
} else if (ch == 'o' || ch == 'O') {
O++;
} else if (ch == 'u' || ch == 'U') {
U++;
}
}
}
}
System.out.println("Vowels A or a: " + A + "\nVowels E or e: " + E + "\nVowels I or i: " + I);
System.out.println("Vowels O or o: " + O + "\nVowels U or u: " + U + "\nTotal Vowels: " + (A + E + I + O + U));
}
}
Find all the practical at one place of Gujarat Technological University(GTU) With Solutions.
Sunday, September 23, 2018
Create a class which ask the user to enter a sentence, and it should display count of each vowel type in the sentence. The program should continue till user enters a word “quit”.
Friday, September 21, 2018
Write a program to find that given number or string is palindrome or not.
import java.util.Scanner;
public class Program_7 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
String rvs = new StringBuffer(str).reverse().toString();
if(str.equals(rvs)){
System.out.println("It is palindrome");
}
else{
System.out.println("It is not palindrome");
}
}
}
Write a program to count the number of words that start with capital letters.
import java.util.Scanner;
public class Program_6 {
public static void main(String[] args) {
int count = 0;
Scanner scan = new Scanner(System.in);
String str = scan.next();
for (int i = 0; i < str.length(); i++) {
if (Character.isUpperCase(str.charAt(i))) {
count++;
}
}
System.out.println("No of Capital Letters:" + count);
}
}
Tuesday, September 18, 2018
Write a program to accept a line and check how many consonants and vowels are there in line
import java.io.*;
class Program_1
{
public static void main(String args[]) throws IOException
{
String str;
int vowels = 0, consonants = 0;
char ch;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a Line : ");
str = br.readLine();
for(int i = 0; i < str.length(); i ++)
{
ch = str.charAt(i);
if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' ||
ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
vowels ++;
else if(Character.isAlphabetic(ch))
consonants ++;
}
System.out.println("Vowels : " + vowels);
System.out.println("Consonants : " + consonants);
}
}
Write a program to find length of string and print second half of the string.
import java.util.Scanner;
public class Program_4 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
System.out.println("Lenght of String : "+str.length());
System.out.println("Print second half : "+str.substring(str.length()/2));
}
}
Write a program to enter two numbers and perform mathematical operations on them.
import java.util.Scanner;
public class Program_3 {
public static void main(String[] args) {
int number1,number2,result;
Scanner scan = new Scanner(System.in);
number1 = scan.nextInt();
number2 = scan.nextInt();
result = number1 + number2;
System.out.println("Sum of two number : "+result);
}
}
Write a program that calculate percentage marks of the student if marks of 6 subjects are given.
import java.util.Scanner;
public class Program_2 {
public static void main(String[] args) {
int marks[] = new int[7];
int total = 0;
float percentage = 0;
Scanner scan = new Scanner(System.in);
for (int i = 1; i <= 6; i++) {
marks[i] = scan.nextInt();
}
for (int i = 1; i <= 6; i++) {
total = total + marks[i];
}
percentage = (total * 100) / 600;
System.out.println("Students percentage = " + percentage);
}
}
Friday, September 14, 2018
Write a program to convert rupees to dollar. 60 rupees=1 dollar
import java.util.Scanner;
public class Program_1 {
public static void main(String[] args) {
int rupees;
double dollar;
Scanner scan = new Scanner(System.in);
rupees = scan.nextInt();
dollar = rupees / 60;
System.out.println(rupees + " Rupees = " + dollar + " Dollar");
}
}
import java.util.Scanner;
public class Program_1 {
public static void main(String[] args) {
int rupees;
double dollar;
Scanner scan = new Scanner(System.in);
rupees = scan.nextInt();
dollar = rupees / 60;
System.out.println(rupees + " Rupees = " + dollar + " Dollar");
}
}
Subscribe to:
Posts (Atom)
-
A country has a capital city A dining philosopher uses a fork A file is an ordinary file or a directory file Files cont...
-
import java.io.*; public class Dataio { public static void main(String args[]) throws IOException { DataInputStr...