Import Public Class Public Static Void New Int Int Int: Source Code
Import Public Class Public Static Void New Int Int Int: Source Code
java
Source Code
import java.util.Scanner;
public class ScannerAdd {
public static void main(String args [])
{ Scanner keyboard= new Scanner(System.in);
System.out.println("Enter two integers: ");
int x=keyboard.nextInt();
int y=keyboard.nextInt();
int z=x+y;
System.out.println("Sum = "+ z);
}
}
Output
Enter two integers:
8
5
Sum = 13
BufferedReader.java
Source Code
import java.io.*;
public class BufferedReader{
public static void main(String[] args) throws IOException{
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
System.out.println("Enter two decimal values:");
String s1 = br.readLine();
String s2 = br.readLine();
Double d1 = Double.parseDouble(s1);
Double d2 = Double.parseDouble(s2);
System.out.println("First: "+d1+"\nSecond: "+d2);
System.out.println("Sum: "+(d1+d2));
System.out.printf("Sum: %.2f",(d1+d2));
}
}
Output
Enter two integers:
3
4
Sum = 7
CommandLineArgument.java
Source Code
public class CommandLineArgument {
public static void main(String ar[]){
int a,b,c;
c=a+b;
System.out.println("sum is " +c);
}
}
}
Output
Enter two integers:
4
6
10
Cylinder.java
Source Code
import java.util.Scanner;
//instance methods
/*------------------------getter*/
public float getheight() {
return height;
}
public float getradius() {
return height;
}
public double areaOfBase() {
return pi*radius*radius;
}
float h,r;
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter the Height and Radius of
Cylinder");
h=keyboard.nextFloat();
r=keyboard.nextFloat();
Output
Enter the Height and Radius of Cylinder
10
15
Surface Area and Volume of cylinder is:
Surface Area: 2356.1925Volume: 7068.5775
Cone.java
Source Code
import java.util.Scanner;
import java.lang.Math;
public class Cone {
//instance variable
private float height,radius;
double pi=3.14159;
//constructor
public Cone(float h,float r){
height=h;
radius =r;
}
//instance methods
/*------------------------getter*/
public float getheight() {
return height;
}
float h,r;
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter the Height and
Radius of Cone");
h=keyboard.nextFloat();
r=keyboard.nextFloat();
}
}
Output
Enter the Height and Radius of Cone
12
19
Surface Area and Volume of cone is:
Surface Area: 3700.79302Volume: 13609.367880000002
CubeTest.java
Source Code
class Cube {
//static class fields
static int length=10;
static int breadth =10;
static int height =10;
//static class methods
static int getvolume() {
return length*breadth*height;
}
}
public class CubeTest {
public static void main(String args[]) {
System.out.println("Length = "+ Cube.length);
System.out.println("Volume of Cube = "+
Cube.getvolume());
}
}
Output
Length = 10
Volume of Cube = 1000
AreaTest.java
Source Code
import java.util.Scanner;
class Area {
//instance variable
private float length,breadth;
//parameterized constructor
public Area(float length,float breadth ) {
this.length=length;
this.breadth=breadth;
}