JPad
Snippets
Download
Help
Contact
If Else Logic Basic Example
Code
int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } Dump("Grade = " + grade);
Result
Console
Grade = C
Bytecode
Compiled from "RunnContainer.java" public class io.jpad.scratch.RunnContainer { public io.jpad.scratch.RunnContainer(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String...) throws java.lang.Exception; Code: 0: bipush 76 2: istore_1 3: iload_1 4: bipush 90 6: if_icmplt 15 9: bipush 65 11: istore_2 12: goto 54 15: iload_1 16: bipush 80 18: if_icmplt 27 21: bipush 66 23: istore_2 24: goto 54 27: iload_1 28: bipush 70 30: if_icmplt 39 33: bipush 67 35: istore_2 36: goto 54 39: iload_1 40: bipush 60 42: if_icmplt 51 45: bipush 68 47: istore_2 48: goto 54 51: bipush 70 53: istore_2 54: new #2 // class java/lang/StringBuilder 57: dup 58: invokespecial #3 // Method java/lang/StringBuilder."<init>":()V 61: ldc #4 // String Grade = 63: invokevirtual #5 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 66: iload_2 67: invokevirtual #6 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder; 70: invokevirtual #7 // Method java/lang/StringBuilder.toString:()Ljava/lang/String; 73: invokestatic #8 // Method io/jpad/scratch/Dumper.Dump:(Ljava/lang/Object;)Ljava/lang/Object; 76: pop 77: return }
Jpad Version:1.04
viewCount:2633
Creator:
admin
Latest Editor:
admin
Tags
ifelse
Download
Copy As Markdown:
**code [If Else Logic Basic Example.java](/example/1n/if-else-logic-basic-example)** int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } Dump("Grade = " + grade); **Result:** Grade = C