<div dir="ltr" style="text-align: left;" trbidi="on">
2. Write a program to pass Starting and Ending limit and print all prime numbers and Fibonacci
numbers between this range.
import java.util.Scanner;
public class Pro2
{
public static void main(String args[])
{
int i,j;
int a = 0, b = 0, c = 1;
Scanner reader = new Scanner(System.in);
System.out.println("Enter Start number(bigger than 2): ");
int Start = reader.nextInt();
System.out.println("Enter End number: ");
int End = reader.nextInt();
for(j=Start;j<end 0="" 120="" 12321="" 153="" 1="" 22="" 329="" 4.write="" 5.="" 5="" 6.="" 6="" 720="" a="" actorial="" an="" and="" are="" args="" armstrong="" b="" break="" c="" canner="" check="" class="" conditional="" count="" digits="" else="" end="" equal="" f="" fact="" factorial="" find="" first="" flag="=1)" for="" i="" ibonacci="" if="" import="" in="new" input:="" int="" integer="" is:="" is="" isn="" it="" j="" java.util.scanner="" java="" largest="n1;" main="" maximum="" n-1="" n1="in.nextInt();" n2="" n3="in.nextInt();" n="" not="" nput="" nter="" num="" number.="" number:="" number="" numbers="" of="" operator="" or="" originalinteger="" orignalinteger="" output:="" p="" palindrome.="" palindrome="" power="" prime="" print="" pro3="" pro4="" pro4_2="" pro5="" pro6="" program="" public="" r="" recursion="" remainder="" return="" reversed="" reversedinteger="" scanner="" second="" series:="" static="" stored="" sum="" system.out.print="" system.out.println="" t="" temp="temp/10;" third="" three="" to="" tring="" using="" variable="" void="" while="" write="" ystem.in="" ystem.out.println=""> largest) {
largest = n2;
}
if (n3 &gt; largest) {
largest = n3;
}
System.out.println("Largest among (" + n1 + ", " + n2 + ", " + n3
+ ") is: "
+ largest);
int smallest = n1;
if (n2 &lt; smallest) {
smallest = n2;
}
if (n3 &lt; smallest) {
smallest = n3;
}
System.out.println("Smallest among (" + n1 + ", " + n2 + ", " + n3
+ ") is: "
+ smallest);
in.close();
}
}
7. Write a java program which should display maximum and minimum number of given 3
numbers.
import java.util.Scanner;
public class Pro7 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter first number: ");
int n1 = in.nextInt();
System.out.println("Enter second number: ");
int n2 = in.nextInt();
System.out.println("Enter third number: ");
int n3 = in.nextInt();
int largest = Math.max(n1, Math.max(n2, n3));
System.out.println("Largest among (" + n1 + ", " + n2 + ", " + n3
+ ") is: "
+ largest);int smallest = Math.min(n1, Math.min(n2, n3));
System.out.println("Smallest among (" + n1 + ", " + n2 + ", " +
n3 + ") is: "
+ smallest);
in.close();
}
}
8. Write a program in Java to multiply two matrix.
import java.util.Scanner;
class Pro8
{
public static void main(String args[])
{
int r1, r2,c1,c2,i,j,k,sum;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows of matrix1");
r1 = in.nextInt();
System.out.println("Enter the number columns of matrix 1");
c1 = in.nextInt();
System.out.println("Enter the number of rows of matrix2");
r2 = in.nextInt();
System.out.println("Enter the number of columns of matrix 2");
c2 = in.nextInt();
if(c1==r2)
{
int mat1[][] = new int[r1][c1];
int mat2[][] = new int[r2][c2];
int res[][] = new int[r1][c2];
System.out.println("Enter the elements of matrix1");
for ( i= 0 ; i &lt; r1 ; i++ )
{
for ( j= 0 ; j &lt; c1 ;j++ )
mat1[i][j] = in.nextInt();
}
System.out.println("Enter the elements of matrix2");for ( i= 0 ; i &lt; r2 ; i++ )
{
for ( j= 0 ; j &lt; c2 ;j++ )
mat2[i][j] = in.nextInt();
}
System.out.println("\n\noutput matrix:-");
for ( i= 0 ; i &lt; r1 ; i++ )
for ( j= 0 ; j <c2 -="" .="" 0="" 1.:="" 10.="" 111="" 112="" 12.="" 13="" 14="" 15.="" 16.="" 17.="" 18.="" 19.="" 19="" 1="" 2-d="" 2.:="" 20.="" 20="" 21.="" 22.="" 23.="" 24.="" 2d="" 3.:="" 3="" 50.="" 50="" 5="" 60="" 9.="" :-="" :="" a1.x="10;" a1="new" a:="" a="" above="" abstract="" access="" accessed="" account.="" account="" accountno="" advance="" all="" also="" alue="" alues="" ame:-="" amount="" an="" and="" ankit="" another="" any="" application="" apply="" appropriate="" ar="" are="" area="" args.length="" args="" arguments="+ args.length);
while(i &lt; args.length) { // Loop until the end of array
System.out.println(args[i] +" around="" arr.length="" arr="" array="" arrays1="s1+args[t];" as="" assign="" atrix="" average="" avg="" avings="" ax="" b1.display="" b1.x="20;" b1="new" b:="" b="" balance="" base="" be="" before="" belongs="" below:="" below="" blank="" block.="" block="" boolean.="" boolean="" both="" but="" bv:="" bv="" by="" byte="" byteobj:="" byteobj="" c1.area="" c1.display="" c1="new" c2="new" c="" calculate="" called="" can="" cannot="" car="" case="" ccount="" ch="" chaining.="" chaining="" change="" changed="" char="" character="" charobj:="" charobj="" check="" circle.="" circle:="" circle="" class.="" class="" classes="" classify.="" classify="" code="" col="" colour="" columns="" command="" company="" company_name="" compile="" compute="" constructed.="" constructor.="" constructor="" constructors="" contain="" containing="" converting="" copy="" copying="" count="" create.="" create="" created.="" created="" creating="" creation="" current="" currentaccount="" cv:="" cv="" d="" data="" declaration.="" declare="" declares="" declaring="" default="" define="" defining="" demonstrate="" deposit="" derive="" describe="" different="" disp="" display="" displaying="" displays="" division="" does="" don="" double="" doubleobj:="" doubleobj="" during="" dv:="" dv="" e="a" each="" econd="" ectangle="" efer="" ehicle="" eight="" eighteen="" ejash="" element="" elements="" eleven="" else="" enable="" end="" ender:-="" enrollmentno="" enter="" equal="" error:="" error="" etc.="" every="" exam="" example="" executed.="" executed="" execution="" exist="" extends="" f="" false.="" fee="" field="" fifteen="" final.="" final="" finaldemo="" find="" first="" five="" float="" floatobj:="" floatobj="" following="" follows="" for="" four="" fourteen="" from="" function.="" function="" functionalities="" functions="" fv:="" fv="" gender:="" gender="" getgender="" getid="" getname="" gets="" getter="" given="" goes="" greater="" h="" haracter.isdigit="" haracter.isletter="" haracter="" has="" hashi="" have="" having="" height="" help="" helps="" here="" hidden="" hides="" hint:="" how="" i.e.="" i="" id:="" id="" if="" illustrates="" implement="" implements="" import="" in.nextint="" in="" ina="" information="" inherit="" initialize="" initialized="" initializer="" initializing="" inside="" instance="" instances="" instantiate="" instantiated.="" int="" integer="" interestrate="" interface="" into="" intobj:="" intobj="" invoked="" invokes="" irst="" is:="" is="" it.="" it="" itself="" iv:="" iv="" j="" jagged="" java.util.scanner="" java="" just="" jvm="" k="" keyword.="" keyword.class="" keyword="" known="" l="" lassify="" length="l;" less="" lets="" letter:="" letter="" like="" line="" loaded="" loat="" loop="" made="" main="" make="" many="" mark="" marks="" mat1="" mat2="" matter="" maxmarks="" may="" member="" members.="" members="" method.="" method="" methods="" modal_type="" model_type="" more="" multipication="" must="" name:="" name="" named="" names="" need="" new="" nine="" nineteen="" no.="" no="" not.="" not="" nsure="" nteger="" nter="" null="" num="" number:="" number="" numbers="" numeric="" nwrapped="" o="" obj.display="" obj.rollno="100;//Remove" obj.run="" obj1.run="" obj1="new" obj="new" objecount="" object.="" object="" objects.public="" objects="" odal="" ode="" of="" ollno="" olour:="" ommon="" ompany="" ompiler="" on.="" once="" one="" only.="" only="" onstructor="" ontents="" opy="" or="" otal="" ote:="" otherwise="" ouble="" output:-="" output="" overdraftlimit.="" overloading="" overridden="" override="" overriding="" parameter="" parameterized="" part="" pass="" patel="" perform="" pi="" possible="" primitive="" print="" printing="" prints="" private="" pro10="" pro14="" pro14_2="" pro15="" pro16="" pro17="" pro18="" pro21="" pro22="" pro23="" pro9="" problem="" program="" programs="" public="" putdata="" q12="" q="" r1.area="" r1.putdata="" r1="new" r2.putdata="" r2="new" r3.putdata="" r3="new" r="" radius="" rather="" rea="" rectangle.objecount="" rectangle:="" rectangle="" refer="" refers="" registered="" res="" result="" retrieving="" return="" returns="" rnum="" roll="" rollno="" row-wise="" row.="" row="" rows="" rowsystem.out.println="" run="" s1.charat="" s1.display="" s1.length="" s1="new" s2.display="" s2="new" same="" savingaccount="" savings="" say="" scanner="" second="" seno="" sequence="" setgender="" setid="" setname="" setter="" seven="" seventeen="" several="" sgender="" shape="" should="" since="" six="" sixteen="" sname="" so="" solution="" specific="" starts..="" statement="" static="" std.disp="" std.gender="M" std.id="1;" std.name="shashi patel" std.setgender="" std.setid="" std.setname="" std="new" string.="" string="" student2="" student3="" student4="" student="" students="" sub="" subclass="" subclasses="" such="" sum="" sumit="" sums="" super.display="" super.x="" super="" superclass="" supposed="" system.out.print="" system.out.println="" t1.area="" t1="new" t="" takes="" task="" tatic="" ten="" test1="" test="" than="" that="" the="" then="" these="" third="" thirteen="" this.fee="fee;" this.gender="gender;" this.id="id;" this.name="name;" this.rollno="rollno;" this="" three="" thrid="" time="" to="" triangle:="" triangle="" tring="" true="" tud="" tudent="" twelve="" two="" type:="" type="" types.="" types="" typesclass="" umber="" understandable="" understanding="" unitsarray="" until="" unwrapping="" uppose="" urrent="" use="" used="" using="" value="" values.="" values="" variable.="" variable="" variables.="" varied="" vehicle="" vehicle_type.="" vehicle_type="" void="" w="" want="" we="" when="" whether="" which="" while="" width="w;" will="" with="" withdraw="" without="" would="" wrapper="" wrapping="" write="" x.="" x="" you="" ystem.in="" ystem.out.println="" yte="">=50)
return true;
else
return false;
}
public String Division(int avg)
{
if(avg&gt;=60)
return "First";
else if(avg&gt;=50)
return "Second";
else
return "No-Division";
}
}
public class Pro24{
public static void main(String[] args) {
boolean pass;
int mark,avg;
String division;
Result res=new Result();
Scanner sc=new Scanner(System.in);
try
{
System.out.println("Enter the mark : ");
mark=sc.nextInt();
System.out.print("Enter the average :");
avg=sc.nextInt();
pass=res.Pass(mark);
division=res.Division(avg);
if(pass)
System.out.println("Passed - "+ division + ".");
else
System.out.println("Failed - " + division+ ".");
}
catch(Exception e)
{
System.out.println("Error : " + e);
}}
}
25. Assume that there are two packages, student and exam. A student package contains
Student class and the exam package contains Result class. Write a program that generates
mark sheet for students.
// Scanner.nextInt method does not read the newline character in your input created by hitting "Enter,"
and so the call to Scanner.nextLine returns after reading that newline.
package Student;
import java.util.Scanner;
public class Student1
{
int a;
String name;
public void getdata()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Name:");
name=sc.nextLine();
System.out.print("Enter the Roll No:");
a=sc.nextInt();
}
public void putdata()
{
System.out.println("Roll No:"+a);
System.out.println("Name :"+name);
}
}
//-----------------------------------------
package Exam;
import Student.*;
import java.util.Scanner;
public class Exam1 extends Student1
{
double m1,m2,m3;
public void getdata()
{
super.getdata();
Scanner sc=new Scanner(System.in);System.out.print("Enter the Marks1:");
m1=sc.nextInt();
System.out.print("Enter the Marks2:");
m2=sc.nextInt();
System.out.print("Enter the Marks3:");
m3=sc.nextInt();
}
public void putdata()
{
super.putdata();
System.out.println("Marks1:"+m1);
System.out.println("Marks2:"+m2);
System.out.println("Marks3:"+m3);
System.out.println("Percentage:"+((m1+m2+m3)/3));
}
}
//-----------------------------------------
import Student.*;
import Exam.*;
class Result
{
public static void main(String s[])
{
Exam1 a1=new Exam1();
a1.getdata();
a1.putdata();
}
}
26. Define a class A in package apack. In class A, three variables are defined of access
modifiers protected, private and public. Define class B in package bpack which extends A and
write display method which accesses variables of class A.
Define class C in package cpack which has one method display() in that create one object of class
A and display its variables. Define class ProtectedDemo in package dpack in which write main ()
method. Create objects of class B and C and class display method for both these objects.
27. Write a java program to implement lambda expression with functional interface in java.28. Write a java program to accept string check whether it is in Upper or Lower case. As per
case change it in according vise versa.
import java.io.*;
class Pro28
{
static String n;
static int l;
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter a String : ");
n = br.readLine();
l = n.length();
changeCase();
}
public static void changeCase()
{
char c;
String b = "";
for(int i=0;i<l c="" i="" if="">=65 &amp;&amp; c&lt;=90)
b+=(char)(c+32);
else
if(c&gt;=97 &amp;&amp; c&lt;=122)
b+=(char)(c-32);
else
b+=c;
}
System.out.println("\nOriginal : " +n);
System.out.println("Changed : " +b);
}
}
OR
import java.io.*;
class Pro28_2
{
public static void main(String args[]) throws IOException
{BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the string");
String s = br.readLine();
int i,l;
char ch;
l=s.length();
for(i=0;i<l 0="" 1="" 29.="" 2="" 30.="" 31.="" :="" a="" an="" are="" args="" array="" be="" because="" both="" by="" called="" can="" cannot="" ch="" class.="" class.you="" class="" classes="" cobj.color="" cobj.x="" cobj.y="" cobj.z="" cobj="new" color="" colored3dpoint="" coloredpoint="" compareto="" comparetoexample="" concat="" concatexample="" create="" declared="" defined="" definitely="" demonstrate="" develop="" dureka="" else="" equal="" equals="" equalsexample="" equalsignorecase="" equalsignorecaseexample="" error="" exception="" extended="" extends="" f="" false="" final.="" final="" for="" further="" greater="" h="" haracter.islowercase="" haracter.isuppercase="" haracter.tolowercase="" haracter.touppercase="" he="" hello="" how="" i="" if="" immutable="" important="" in="" inheritance.="" inherited="" int="" intlen="palindrome.length();" is="" isempty="" isemptyexample="" it="" ivide="" java="" keyword="" l="" len="" length="" like="" lower="" m="" main="" make="" making="" methods="" not="" num1="15," num2="0;" of="" one="" only="" other="" palindrome="Dot saw I was Tod" point="" predefined="" prevent="" pro30="" pro31="" program="" public="" publicclassstringdemo="" publicstaticvoidmain="" rainforce="" replace="" replaceexample1="" replaceexample2="" replacestring="" result="" returns="" s1.compareto="" s1.equalsignorecase="" s1.isempty="" s1.trim="" s1="" s1upper="" s2.isempty="" s2="hello" s3="" s4="" static="" string="" stringlowerexample="" stringtrimexample="" system.out.prinltn="" system.out.print="" system.out.println="" t="" than="" the="" there="" time="" times="" to="" tolowercase="" trim="" tring="" tringargs="" true="" try="" two="" use="" user="" uses="" void="" when="" with="" without="" write="" x="
System.out.println(" y="
System.out.println(" you="" z="
System.out.println(" zero="">=0; i--) {
System.out.println("The value of array is"
+array[i]);
}
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Error. Array is out of Bounds"+e);
} catch (ArithmeticException e) {
System.out.println ("Can't be divided by Zero"+e);
}
}
}32. Write a program in Java to demonstrate throw, throws, finally, multiple try block and multiple
catch exception.
33. Write a small application in Java to develop Banking Application in which user deposits the
amount Rs 1000.00 and then start withdrawing of Rs 400.00, Rs 300.00 and it throws exception
"Not Sufficient Fund" when user withdraws Rs. 500 thereafter
import java.util.Scanner;
class account
{
int fund;
void deposite(int fund)
{
this.fund=fund;
}
void withdraw(int w) throws Exception
{
fund=fund-w;
if(fund</l></l></c2></end></div>

Pc Ki Videos