19BIT0422-Prajesh Raj Singh

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

19BIT0422- Prajesh Raj Singh

Q1.
package javalabdemo;
import java.io.*;
public class prog1
{
public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
String uName,pass,cpass;
System.out.print("Enter the username:");
uName=in.readLine();
System.out.print("Enter the password:");
pass=in.readLine();
if((uName.isEmpty()==true)&&(pass.isEmpty()==true))
{
System.out.println("The username and password is empty, hence
program is terminated");
}
else
{
System.out.println("The username and password is filled");

if((uName.isEmpty()==false)&&(pass.isEmpty()==false))
{
System.out.println("The password contains the
username");
}
else if((uName.isEmpty()==true)&&(pass.isEmpty()==false))
{
System.out.println("The password does no contain the
username");
}
}
if(pass.length()>=8)
{
System.out.println("The password is valid");
System.out.print("Confirm the password:");
cpass=in.readLine();
if(cpass.equals(pass)==true)
{
System.out.println("Confirm password");

}
else
{
System.out.println("Confirm password");

}
}
else
{
System.out.println("The password is invalid, reenter the
password");
}
}
}
19BIT0422- Prajesh Raj Singh

Q2.
package javalabdemo;
import java.io.*;
public class prog1
{
public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
int i,j,c=0;
String A[]=new String[5];
String B[]=new String[5];
String t="";
System.out.println("Enter the registration numbers:");
for(i=0;i<5;i++)
{
A[i]=in.readLine();
}
for(i=0;i<5;i++)
{
if((A[i].substring(2,5)).equals("BEC"))
{
System.out.println(A[i]+" Registration ID invalid");
}
else
{
B[c]=A[i];
c++;
}
}
for(i=0;i<c;i++)
{
for(j=0;j<(c-i-1);j++)
{
if((B[j].compareTo(B[j+1])>1))
{
t=B[j];
B[j]=B[j+1];
B[j+1]=t;
}
}
}
System.out.println("The sorted array is:");
for(i=0;i<c;i++)
{
19BIT0422- Prajesh Raj Singh
System.out.println(B[i]);
}
}
}

Q3.
package javalabdemo;
import java.io.*;
public class prog1
{
public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
int i,l=0;
String s,revf="",rev="";
char chr;
System.out.println("Enter the string:");
s=in.readLine();
s=s+" ";
l=s.length();
for(i=0;i<l;i++)
{
chr=s.charAt(i);
if(chr!=' ')
{
rev=chr+rev;
}
else
{
revf=revf+" "+rev;
rev="";
}
}
19BIT0422- Prajesh Raj Singh
System.out.println("The modified string is: "+revf);
}
}

Q4.
package javalabdemo;
import java.io.*;
public class word_count
{
public static void main(String[] args)throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a string:");
String s=in.readLine();
String[] uni= new String[10];
int size=0;
boolean flag;
for(String x: s.split(" ")) {
flag=true;
for (String y : uni)
if (x.equals(y)){
flag=false;
break;
}
if (flag){
uni[size]=x;
size++;
}
}
int c;
for(String x:uni)
{
c=0;
if(x!=null)
{
for (String y : s.split(" "))
if (x.compareTo(y) == 0)
c++;
System.out.println("Frequency of "+ x + " is " + c);
}
}
}
}
19BIT0422- Prajesh Raj Singh

Q5.
package javalabdemo;
import java.io.*;
public class prog1
{
public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
int i,l=0,c=0;
String s;
char chr;
System.out.println("Enter the string:");
s=in.readLine();
l=s.length();
for(i=0;i<l;i++)
{
chr=s.charAt(i);

if((Character.toLowerCase(chr)=='a')||(Character.toLowerCase(chr)=='e')||(C
haracter.toLowerCase(chr)=='i')||(Character.toLowerCase(chr)=='o')||(Character.toL
owerCase(chr)=='u'))
{
c++;
}
}
System.out.println("The number of vowels in the string="+c);

}
19BIT0422- Prajesh Raj Singh

Q6.
package javalabdemo;
import java.io.*;
public class prog1
{
public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
int i,l=0,ascii=0,l2=0;
char chr;
String s,hexString="",bin="";
System.out.println("Enter a string:");
s=in.readLine();
l=s.length();
for(i=0;i<l;i++)
{
chr=s.charAt(i);
ascii=(int)chr;
hexString=hexString+(Integer.toHexString(ascii));
}
l2=hexString.length();
for(i=0;i<l2;i++)
{
chr=hexString.charAt(i);
switch(chr)
{
case '0':
bin=bin+"0000";
break;
case '1':
bin=bin+"0001";
break;
case '2':
bin=bin+"0010";
break;
case '3':
bin=bin+"0011";
break;
case '4':
bin=bin+"0100";
break;
case '5':
bin=bin+"0101";
break;
case '6':
bin=bin+"0110";
break;
case '7':
bin=bin+"0111";
break;
case '8':
bin=bin+"1000";
break;
case '9':
bin=bin+"1001";
break;
19BIT0422- Prajesh Raj Singh
case 'A':
bin=bin+"1010";
break;
case 'B':
bin=bin+"1011";
break;
case 'C':
bin=bin+"1100";
break;
case 'D':
bin=bin+"1101";
break;
case 'E':
bin=bin+"1110";
break;
case 'F':
bin=bin+"1111";
break;
}
}
System.out.println("The binary equivalent is:"+bin);
}
}

Q7.
package javalabdemo;
import java.io.*;
public class password_check
{
public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your username : ");
String username = in.readLine();
System.out.println("Enter your password");
String password = in.readLine(); String temp;
for (int i = 0; i < username.length() - 2; i++)
{
temp = username.substring(i, i + 3);
if (password.contains(temp))
{
System.out.println("Weak password");
break;
}
}
}
}
19BIT0422- Prajesh Raj Singh

Q8.
package javalabdemo;
import java.io.*;
public class search
{
public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
int i,k=0;
String A[]=new String[5];
System.out.println("Enter the names:");
for(i=0;i<5;i++)
{
A[i]=in.readLine();
}
String ns;
System.out.println("Enter the name to be searched:");
ns=in.readLine();
for(i=0;i<5;i++)
{
if(A[i].equals(ns)==true)
{
k=1;
break;
}
}
if(k==1)
{
System.out.println("The name is found");
}
else
{
System.out.println("The name is not found")
}
}
}
19BIT0422- Prajesh Raj Singh

Q10.
package javalabdemo;
import java.io.*;
public class Products
{
public String pId, Pname, Pcom, Pmfd;
public int Pprice, Psno;
public boolean searchByCompany(String comp)
{
if (this.Pcom.equals(comp))
return true;
else
return false;
}
public String searchByMfd()
{
return this.Pmfd.substring(6);
}
public boolean searchByPrice(int price)
{
if (this.Pprice > price)
return true;
else
return false;
}
public boolean searchByCategory(String category)
{
if (this.Pname.contains(category))
return true;
else
return false;
}
}
class products_main
{
public static void main(String[] args)throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Products[] prod = new Products[5];
int i, num; String data;
for(i=0;i<5;i++)
{
prod[i] = new Products();
}
for (i = 0; i < 5; i++)
{
prod[i].Psno = i;
19BIT0422- Prajesh Raj Singh
System.out.println("Enter Product ID");
data = in.readLine();
prod[i].Pname = data;
System.out.println("Enter Product name");
data = in.readLine();
prod[i].pId = data;
System.out.println("Enter Company name");
data = in.readLine();
prod[i].Pcom = data;
System.out.println("Enter Manufacture date");
data = in.readLine();
prod[i].Pmfd = data;
System.out.println("Enter Price");
num = Integer.parseInt(in.readLine());
prod[i].Pprice = num;
}
System.out.println("products by Samsung company");
for (Products obj: prod)
if (obj.searchByCompany("Samsung"))
System.out.println(obj.pId+ " " + obj.Pname + " " +
obj.Pprice);
System.out.println("products manufactured between 2012 and
2019");
for (Products obj: prod)
if (obj.searchByMfd().compareTo("2012") > 0 &&
obj.searchByMfd().compareTo("2019") < 0)
System.out.println(obj.pId + " " + obj.Pname + " " +
obj.Pprice);
System.out.println("Products with price greater than 10000");
for (Products obj: prod)
if (obj.searchByPrice(10000))
System.out.println(obj.pId + " " + obj.Pname + " " +
obj.Pprice);
System.out.println("Products with laptop in their name");
for (Products obj: prod)
if (obj.searchByCategory("Laptop"))
System.out.println(obj.pId + " " + obj.Pname + " " +
obj.Pprice);
}
}

You might also like