Вы находитесь на странице: 1из 18

Enrollment No.

:171120107034

Practical: 01
Aim: Write a program to convert rupees to dollar. 60 rupees=1 dollar
INPUT
import java.util.Scanner;
class convert
{
public static void main( String [] args )
{
Double r,d;
Scanner sc = new Scanner( System.in );
System.out.println("171120107031");
System.out.println("Enter RS.");
r = sc.nextDouble();
d = r/60;
System.out.println("RS = "+r+" is d = "+d);
}
}

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

OUTPUT

Fig.:01 Convert rupees to dollar

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

Practical: 02
Aim: Write a program that calculate percentage marks of the student if
marks of 6 subjects are given.
INPUT
import java.util.Scanner;
class Sub
{
public static void main( String [] args )
{
int mark[] = new int[6];
int i,sum=0,per;
Scanner sc = new Scanner(System.in);
System.out.println("171120107031");
System.out.println("Enter marks of all subjects");
for(i=0;i<6;i++)
{
mark[i] = sc.nextInt();
sum =sum + mark[i];
}
per = (sum/6);
System.out.println("Percentage = "+per+"%");
}
}

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

OUTPUT

Fig.:02 Implementation of program that calculate percentage marks of the


student injava

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

Practical:03
Aim: Write a program to enter two numbers and perform
mathematical operation on them.
INPUT
import java.util.Scanner;
class cal
{
public static void main( String [] args )
{
int a,b;
Scanner sc = new Scanner (System.in);
System.out.println("171120107031");
System.out.println("Enter value of a");
a = sc.nextInt();
System.out.println("Enter value of b");
b = sc.nextInt();
System.out.println("Addition = "+(a+b));
System.out.println("Subtraction = "+(a-b));
System.out.println("Multiplication = "+(a*b));
System.out.println("Division = "+(a/b));
}
}

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

OUTPUT

Fig.:03 Enter two numbers and perform mathematical operations

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

Practical:04
Aim: Write a program to find length of string and print second half of the
string.
INPUT
import java.util.*;
class substring
{
public static void main(String m[])
{
Scanner in=new Scanner(System.in);
String s=new String();
System.out.println("171120107031");
System.out.println("Enter a String :");
s=in.next();
int l=s.length();
System.out.println("Length of the string "+s+" is "+l);
System.out.println("Your sub String is:"+s.substring(l/2));
}
}

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

OUTPUT

Fig.:04 Find length of string and print second half of the string

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

Practical:05
Aim: Write a program to accept a line and check how many consonantsand
vowels are there in line.
INPUT
import java.util.*;
class vowels
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
String s=new String();
System.out.println("171120107031");
System.out.println("Enter a line:");
s=in.nextLine();
char c;
int sp=0,cl=0,cv=0,cs=0,ci=0;
for ( inti=0;i<s.length();i++)
{
c=s.charAt(i);
if(c>=65 && c<=90 || c>=97 && c<=122)
{
cl++;
if(c=='A' || c=='E' || c=='I' || c=='O' || c=='U'|| c=='a' || c=='e' ||
c=='i' || c=='o' || c=='u')
cv++;
}
else if(c>=48 && c<=57)
{
ci++;

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107031

}
else if(c==' ')
{
sp++;
}
else
{
cs++;
}
}
System.out.println("total number of alphabet in this string is "+cl);
System.out.println("total number of vowel in this string is "+cv);
System.out.println("total number of consonant in this string is "+(cl-cv));
System.out.println("total number of digit in this string is "+ci);
System.out.println("total number of space in this string is "+sp);
System.out.println("total number of special char in this string is "+cs);
}
}

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

OUTPUT

Fig.:05 Check how many consonants and vowels

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

Practical:06
Aim: Write a program to count the number of words that starts with
capital letters.
INPUT
import java.lang.*;
import java.util.*;
class capital
{
public static void main(String args[])
{
int count = 0;
Scanner scan = new Scanner(System.in);
System.out.println("171120107031");
System.out.println("enter string");
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);
}

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

OUTPUT

Fig.:06 Count the number of words that start with capital letters

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

Practical:07
Aim: Write a program to find that given number or string is palindrome or
not.
INPUT
import java.lang.*;
import java.util.*;
class palindrome
{
public static void main(String args[])
{
String str, rev = "";
Scanner sc = new Scanner(System.in);
System.out.println("171120107031");
System.out.println("Enter a string:");
str = sc.nextLine();
int length = str.length();
for ( inti = length - 1; i>= 0; i-- )
rev = rev + str.charAt(i);
if (str.equals(rev))
System.out.println(str+" is a palindrome");
else
System.out.println(str+" is not a palindrome");
}
}

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

OUTPUT

Fig.:07 Find that given number or string is palindrome or not

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

Practical:08
Aim: 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”.
INPUT
import java.util.*;
class count
{
public static int a,e,i,o,u;
public static void main(String args[])
{
System.out.println("171120107031");
Scanner in=new Scanner(System.in);
String s=new String();
while(true)
{
int ta=0,te=0,ti=0,to=0,tu=0;
System.out.println("Enter a line : \n");
s=in.nextLine();
if(s.equals("quit"))
{
break;
}
else
{
int n=s.length()-1;
for(int x=0;x<=n;x++)
{
switch(s.charAt(x))
{
PSE\CE-SEM-V\JAVA Page No:
Enrollment No.:171120107034

case 'a' : case 'A' : a++; ta++; break;


case 'e' : case 'E' : e++; te++;break;
case 'i' : case 'I' : i++; ti++; break;
case 'o' : case 'O' : o++; to++; break;
case 'u' : case 'U' : u++; tu++; break;
}
}
System.out.println("\nIn this statement:\n");
System.out.println("a comes: "+ta+" times");
System.out.println("e comes :"+te+" times");
System.out.println("icomes :"+ti+" times");
System.out.println("o comes: "+to+" times");
System.out.println("u comes :"+tu+" times \n");
}
}
System.out.println("\nTotle numbers of the vovels::");
System.out.println("a comes "+a+" times");
System.out.println("e comes "+e+" times");
System.out.println("i comes "+i+" times");
System.out.println("o comes "+o+" times");
System.out.println("u comes "+u+" times");
}
}

PSE\CE-SEM-V\JAVA Page No:


Enrollment No.:171120107034

OUTPUT

Fig.:08Display count of each vowel type in the sentence

PSE\CE-SEM-V\JAVA Page No:

Вам также может понравиться