0% found this document useful (0 votes)
3 views9 pages

PJ 1

Uploaded by

MONICA NAHAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

PJ 1

Uploaded by

MONICA NAHAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Dt : 29/7/2023(Solution)

Assignment:

Update above program by displaying result as follows:

pr=>

70 to 100 ===> Distiction

i
60 to <70 ===> FirstClass

thi
50 to <60 ===> SecondClass

35 to <50 ===> ThirdClass

ipa
else ===> Fail

SubClass : SudentResult
Ma
String res(float per)
sh
ate

Program : StudentMainClass.java(Modified program)

import java.util.Scanner;
nk

class StudentResult

{
Ve

String res(float pr)

if(pr>=70 && pr<=100)

return "Distinction";
}

else if(pr>=60 && pr<70)

return "FirstClass";

i
else if(pr>=50 && pr<60)

thi
{

return "SecondClass";

ipa
}

else if(pr>=35 && pr<50)

{
Ma
return "ThirdClass";
sh
}
ate

else

{
nk

return "Fail";

}
Ve

class Percentage

float per(int totMarks)


{

float p = (float)totMarks/6;

return p;

i
class StuMainClass

thi
{

public static void main(String[] args)

ipa
{
Ma
Scanner s = new Scanner(System.in);

int i=1,totMarks=0;

while(i<=6)
sh
{
ate

System.out.println("Enter marks of sub-"+i);

int sub = s.nextInt();


nk

if(sub<0 || sub>100)

{
Ve

System.out.println("Invalid marks...");

continue;

totMarks=totMarks+sub;

i++;
}

System.out.println("TotalMarks:"+totMarks);

Percentage ob = new Percentage();

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

Enter marks of sub-2

46
nk

Enter marks of sub-3

52
Ve

Enter marks of sub-4

43

Enter marks of sub-5

44

Enter marks of sub-6


45

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

is checked,this process is repeated until the condition is false.

syntax:
nk

do
Ve

//loop_body

while(condition);
FlowChart:

i
thi
ipa
Ma
sh
ate

===================================================================
nk

====

(c)for loop:
Ve

=>for-loop is more simple in representation when compared to while and do-


while

loops,because Initialization,Condition and Incre/Decre are declared in the same


line

separated by SemiColon.
syntax:

for(Initialization;Condition;Incre/Decre)

//Loop_body

i
thi
Flowchart:

ipa
Ma
sh
ate
nk

===================================================================
=====
Ve

Ex:

wap to read a number and display the factorial?

program : DemoFor.java
import java.util.Scanner;

class DemoFor

public static void main(String[] args)

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:

Enter the value n:

Factorial=24
===================================================================
=====

i
thi
ipa
Ma
sh
ate
nk
Ve

You might also like