0% found this document useful (0 votes)
5 views

Java Programs

Cpp

Uploaded by

rp218242
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Programs

Cpp

Uploaded by

rp218242
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

200+ Java Programs with Outputs

1. Hello World
public class HelloWorld {

public static void main(String[] args) {

System.out.println("Hello, World!");

Output: Hello, World!

2. Simple Calculator
import java.util.Scanner;

public class SimpleCalculator {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter first number: ");

double num1 = sc.nextDouble();

System.out.print("Enter second number: ");

double num2 = sc.nextDouble();

System.out.print("Sum: " + (num1 + num2));

Output: Sum: [calculated value]

3. Fibonacci Series
import java.util.Scanner;

public class Fibonacci {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

System.out.print("Enter number of terms: ");

int n = sc.nextInt();

int a = 0, b = 1;

System.out.print("Fibonacci Series: ");

for (int i = 1; i <= n; i++) {

System.out.print(a + " ");

int next = a + b;

a = b;

b = next;

Output: [Fibonacci series output]

You might also like