Java Programming Examples and User Registration Forms

Posted by Anonymous and classified in Computers

Written on in English with a size of 2.08 KB

User Registration Form

Name:

Password:

Gender:
Male
Female

Hobbies:
Reading
Music

City:
SuratAhmedabad

Java Programming Examples

1. Simple Interest Calculation

import java.util.Scanner;
class SimpleInterest {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        float p, r, t, si;
        p = sc.nextFloat();
        r = sc.nextFloat();
        t = sc.nextFloat();
        si = (p * r * t) / 100;
        System.out.println("Simple Interest = " + si);
    }
}

2. Call Cost Calculation

import java.util.Scanner;
class CallCost {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int min;
        float rate, cost;
        min = sc.nextInt();
        rate = sc.nextFloat();
        cost = min * rate;
        System.out.println("Call Cost = " + cost);
    }
}

3. Basic Arithmetic Operations

import java.util.Scanner;
class Arithmetic {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a, b;
        a = sc.nextInt();
        b = sc.nextInt();
        System.out.println("Add = " + (a + b));
        System.out.println("Sub = " + (a - b));
    }
}

4. Pass or Fail Logic

import java.util.Scanner;
class PassFail {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        if (m >= 35)
            System.out.println("Pass");
        else
            System.out.println("Fail");
    }
}

5. Room Area Class Example

class Room {
    int l, w;
    void set(int a, int b) {
        l = a; w = b;
    }
    int area() {
        return l * w;
    }
}
class RoomDemo {
    public static void main(String args[]) {
        Room r = new Room();
        r.set(10, 12);
        System.out.println(r.area());
    }
}

Related entries: