Home / Programs / abs() Method in java Example 2
🚀 Programming Example

abs() Method in java Example 2

👁 914 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

💻 Program Code

 public class AbsMethod {

 public static void main(String args[]) {
	 
 Integer a = -8;
 double d = -100;
 float f = -90;
 long l = -7878l;
 byte b = -84;
 short s = -4;

 System.out.println(Math.abs(a));
 System.out.println(Math.abs(d));
 System.out.println(Math.abs(f));
 System.out.println(Math.abs(l));
 System.out.println(Math.abs(b));
 System.out.println(Math.abs(s));

   }
}
                        

🖥 Program Output

8
100.0
90.0
7878
84
4
Press any key to continue . . .
                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.