PJ 1
PJ 1
Assignment:
pr=>
i
60 to <70 ===> FirstClass
thi
50 to <60 ===> SecondClass
ipa
else ===> Fail
SubClass : SudentResult
Ma
String res(float per)
sh
ate
import java.util.Scanner;
nk
class StudentResult
{
Ve
return "Distinction";
}
return "FirstClass";
i
else if(pr>=50 && pr<60)
thi
{
return "SecondClass";
ipa
}
{
Ma
return "ThirdClass";
sh
}
ate
else
{
nk
return "Fail";
}
Ve
class Percentage
float p = (float)totMarks/6;
return p;
i
class StuMainClass
thi
{
ipa
{
Ma
Scanner s = new Scanner(System.in);
int i=1,totMarks=0;
while(i<=6)
sh
{
ate
if(sub<0 || sub>100)
{
Ve
System.out.println("Invalid marks...");
continue;
totMarks=totMarks+sub;
i++;
}
System.out.println("TotalMarks:"+totMarks);
float pr = ob.per(totMarks);
System.out.println("Percentage:"+pr);
i
StudentResult sr = new StudentResult();
thi
String result = sr.res(pr);
System.out.println("Result:"+result);
ipa
}
o/p:
Ma
Enter marks of sub-1
sh
45
ate
46
nk
52
Ve
43
44
TotalMarks:275
Percentage:45.833332
Result:ThirdClass
===================================================================
========
i
thi
Assignment:
Update above program by displaying result as "Fail",if any one Subject marks
ipa
are
in b/w 0 to 34
Ma
===================================================================
======
(b)do-while loop
sh
=>In do-while looping structure the loop-body is executed first and then
condition
ate
syntax:
nk
do
Ve
//loop_body
while(condition);
FlowChart:
i
thi
ipa
Ma
sh
ate
===================================================================
nk
====
(c)for loop:
Ve
separated by SemiColon.
syntax:
for(Initialization;Condition;Incre/Decre)
//Loop_body
i
thi
Flowchart:
ipa
Ma
sh
ate
nk
===================================================================
=====
Ve
Ex:
program : DemoFor.java
import java.util.Scanner;
class DemoFor
i
Scanner s = new Scanner(System.in);
thi
System.out.println("Enter the value n:");
int n = s.nextInt();
ipa
int fact=1;
{
for(int i=n;i>=1;i--)
Ma
fact=fact*i;
sh
}
ate
System.out.println("Factorial="+fact);
}
nk
}
Ve
o/p:
Factorial=24
===================================================================
=====
i
thi
ipa
Ma
sh
ate
nk
Ve