• Apex Beginner
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hello,

I am beginner in Salesforce and still in initial steps in understanding the concepts..i tried the below class and the output didnt come as expected 

public class mytest2 
{
    Public integer marks;
    Public string result;
        {
        if(marks >= 35 && marks <= 50)
        result = 'passed';
        else if (marks >= 51 && marks <= 70)
        result = 'B';
        else if (marks >= 71)
        result ='A';
        else 
        result = 'failed';
                {
                  system.debug('Your results:' + result);
                }
        }    
}

and executing it in anonymous window 

mytest2 c1 = new mytest2();
c1.marks = 55;
system.debug(c1);

Output was Your results:failed

which seems to be wrong ..not sure what went wrong here
Hello,

I am beginner in Salesforce and still in initial steps in understanding the concepts..i tried the below class and the output didnt come as expected 

public class mytest2 
{
    Public integer marks;
    Public string result;
        {
        if(marks >= 35 && marks <= 50)
        result = 'passed';
        else if (marks >= 51 && marks <= 70)
        result = 'B';
        else if (marks >= 71)
        result ='A';
        else 
        result = 'failed';
                {
                  system.debug('Your results:' + result);
                }
        }    
}

and executing it in anonymous window 

mytest2 c1 = new mytest2();
c1.marks = 55;
system.debug(c1);

Output was Your results:failed

which seems to be wrong ..not sure what went wrong here