//Absolute value using conditional operator
import java.util.Scanner;
class Absolute {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no:");
int no=sc.nextInt();
int a=(no<0)?no*(-1):no;
System.out.println("Absolute value:"+a);
}
}
import java.util.Scanner;
class Absolute {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no:");
int no=sc.nextInt();
int a=(no<0)?no*(-1):no;
System.out.println("Absolute value:"+a);
}
}
No comments:
Post a Comment