1) Class absolute
Public static void main (string args[])
Int x , y ;
X = 10 ;
Y = x < 0 ? -x : x ; // Find absolute value of x
[Link](“ Absolute value of ”) ;
[Link]( x + “ is “ + y ) ;
X = -10 ;
Y = x < 0 ? -x : x ; // Find absolute value of x
[Link](“ Absolute value of ”) ;
[Link]( x + “ is “ + y ) ;
Output:-
Absolute value of 10 is 10
Absolute value of -10 is 10
2) class calculate
Public static void main (string args[])
Int num1 = 20 ;
Int num2 = 30 ;
Int tot;
Tot = num1 + num2 ;
[Link](“ total of “ + num1 + “ and ” + num2 + “ is “ + tot) ;
Output:-
Total of 20 and 30 is 50
3) class modulus
Public static void main (string args[])
Int num1 = 250 ;
Double num2 = 460.25 ;
[Link],println( “ num1 mod 10 = “ + num1 % 10 ) ;
[Link]( “ num2 mod 10 = “ + num2 % 10 ) ;
Output:-
Num1 mod 10 = 0
Num2 mod 10 = 0.25
4) import [Link] ;
Class arearect
Public static void main ( string args[] )
Scanner rectangle = new scanner( [Link] ) ;
long len,bre ;
[Link](“enter length of rectangle “) ;
Len = [Link] ( ) ;
[Link](“Enter breadth of rectangle “) ;
Bre = [Link]() ;
[Link](“ Area of rectangle is “ + (len*bre) ) ;
Output:- Enter length of rectangle
289400
Enter breath of rectangle
43800
Area of rectangle is 12675720000
5) import [Link];
public class HelloWorld {
public static void main(String[] args) {
// Creates a reader instance which takes
// input from standard input - keyboard
Scanner reader = new Scanner([Link]);
[Link]("Enter a number: ");
// nextInt() reads the next integer from the keyboard
int number = [Link]();
// println() prints the following line to the output screen
[Link]("You entered: " + number);
}
}
Output:- Enter a number : 10
You entered : 10