1) Class absolute
Public static void main (string args[])
Int x , y ;
X = 10 ;
Y = x < 0 ? -x : x ; // Find absolute value of x
System.out.print(“ Absolute value of ”) ;
System.out.println( x + “ is “ + y ) ;
X = -10 ;
Y = x < 0 ? -x : x ; // Find absolute value of x
System.out.print(“ Absolute value of ”) ;
System.out.println( 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 ;
System.out.println(“ 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 ;
System.out,println( “ num1 mod 10 = “ + num1 % 10 ) ;
System.out.println( “ num2 mod 10 = “ + num2 % 10 ) ;
Output:-
Num1 mod 10 = 0
Num2 mod 10 = 0.25
4) import java.util.scanner ;
Class arearect
Public static void main ( string args[] )
Scanner rectangle = new scanner( system.in ) ;
long len,bre ;
System.out.println(“enter length of rectangle “) ;
Len = rectangle.nextlong ( ) ;
System.out.println(“Enter breadth of rectangle “) ;
Bre = rectangle.nextLong() ;
System.out.println(“ Area of rectangle is “ + (len*bre) ) ;
Output:- Enter length of rectangle
289400
Enter breath of rectangle
43800
Area of rectangle is 12675720000
5) import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
// Creates a reader instance which takes
// input from standard input - keyboard
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
// nextInt() reads the next integer from the keyboard
int number = reader.nextInt();
// println() prints the following line to the output screen
System.out.println("You entered: " + number);
}
}
Output:- Enter a number : 10
You entered : 10