NAME AND AGE
package Demo1;
import java.util.*;
public class example1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Age: ");
int age = sc.nextInt();
System.out.println("Name: " + name + '\n' + "Age: " + age);
}
}
RESULTS:
Enter Name: Thea
Enter Age: 19
Name: Thea
Age: 19
SUM
package Demo1;
import java.util.*;
public class example1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int fnum = sc.nextInt();
System.out.print("Enter second number: ");
int snum = sc.nextInt();
int sum = fnum + snum;
System.out.println("Sum: " + sum);
}
}
RESULTS:
Enter first number: 354
Enter second number: 435
Sum: 789
,SPEED
package Demo1;
import java.util.*;
public class example1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int distance = 1000;
System.out.print("Enter the time of the car: ");
int time = sc.nextInt();
int speed = distance/time;
System.out.println("Speed: " + speed);
}
}
RESULTS:
Enter the time of the car: 100
Speed: 10
CIRCUMFERENCE
package Demo1;
import java.util.*;
public class example1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
double pi = 3.14;
System.out.print("Enter the radius of the circle: ");
int radius = sc.nextInt();
double circumference = 2 * (pi * radius);
System.out.println("Circumference: " + circumference);
}
}
RESULTS:
Enter the radius of the circle: 2
Circumference: 12.56
RADIUS
package Demo1;
import java.util.*;
public class example1 {
, public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
double pi = 3.14;
System.out.print("Enter the circumference of the circle: ");
double circumference = sc.nextDouble();
double radius = circumference / (2 * pi);
System.out.println("Radius: " + radius);
}
}
RESULTS:
Enter the circumference of the circle: 12.56
Radius: 2.0
Connected classes
//1st class name: example1
package Demo1;
import java.util.*;
public class example1
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner scan = new Scanner (System.in);
System.out.print("Enter first num: ");
int fnum = scan.nextInt();
System.out.print("Enter second num: ");
int snum = scan.nextInt();
System.out.println("");
test test = new test ();
test.addNum(fnum, snum);
}
}
//2nd class name: test
package Demo1;
public class test {
public int sum;
void addNum (int num1, int num2) {
package Demo1;
import java.util.*;
public class example1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Age: ");
int age = sc.nextInt();
System.out.println("Name: " + name + '\n' + "Age: " + age);
}
}
RESULTS:
Enter Name: Thea
Enter Age: 19
Name: Thea
Age: 19
SUM
package Demo1;
import java.util.*;
public class example1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int fnum = sc.nextInt();
System.out.print("Enter second number: ");
int snum = sc.nextInt();
int sum = fnum + snum;
System.out.println("Sum: " + sum);
}
}
RESULTS:
Enter first number: 354
Enter second number: 435
Sum: 789
,SPEED
package Demo1;
import java.util.*;
public class example1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int distance = 1000;
System.out.print("Enter the time of the car: ");
int time = sc.nextInt();
int speed = distance/time;
System.out.println("Speed: " + speed);
}
}
RESULTS:
Enter the time of the car: 100
Speed: 10
CIRCUMFERENCE
package Demo1;
import java.util.*;
public class example1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
double pi = 3.14;
System.out.print("Enter the radius of the circle: ");
int radius = sc.nextInt();
double circumference = 2 * (pi * radius);
System.out.println("Circumference: " + circumference);
}
}
RESULTS:
Enter the radius of the circle: 2
Circumference: 12.56
RADIUS
package Demo1;
import java.util.*;
public class example1 {
, public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
double pi = 3.14;
System.out.print("Enter the circumference of the circle: ");
double circumference = sc.nextDouble();
double radius = circumference / (2 * pi);
System.out.println("Radius: " + radius);
}
}
RESULTS:
Enter the circumference of the circle: 12.56
Radius: 2.0
Connected classes
//1st class name: example1
package Demo1;
import java.util.*;
public class example1
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner scan = new Scanner (System.in);
System.out.print("Enter first num: ");
int fnum = scan.nextInt();
System.out.print("Enter second num: ");
int snum = scan.nextInt();
System.out.println("");
test test = new test ();
test.addNum(fnum, snum);
}
}
//2nd class name: test
package Demo1;
public class test {
public int sum;
void addNum (int num1, int num2) {