0% found this document useful (0 votes)
3 views10 pages

Write A Java Program To Print Simple Message

The document contains ten Java programs demonstrating basic programming concepts. These include printing messages, variable declaration, simple interest calculation, arithmetic operations, user input, factorial calculation, array access, even/odd checking, prime number checking, and displaying the alphabet using a loop. Each program is accompanied by its respective output.

Uploaded by

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

Write A Java Program To Print Simple Message

The document contains ten Java programs demonstrating basic programming concepts. These include printing messages, variable declaration, simple interest calculation, arithmetic operations, user input, factorial calculation, array access, even/odd checking, prime number checking, and displaying the alphabet using a loop. Each program is accompanied by its respective output.

Uploaded by

ndhaliwal4490
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. Write a java program to print a simple message.

public class first1

public static void main(String[] args)

[Link]("hello world welcome in Java");

[Link]("How are you");

OUTPUT:-
[Link] a java program to declare and initialization of variable.

public class abcd

public static void main(String[] args)

int n=10;

[Link](n);

OUTPUT:-
[Link] a java program to perform simple interest calculation.

import [Link];

public class si

public static void main(String[] args)

float p=1,r=1,t=1;

float SI=(p*r*t)/100;

[Link]("simple interest: " +SI);

OUTPUT:-
[Link] a java program to perform arithmetic operators.

public class op

public static void main(String args[ ])

int a=10;

int b=20;

[Link]("a+b="+(a+b));

[Link]("a*b="+(a*b));

OUTPUT:-
[Link] a java program to accept data from user.

import [Link];

public class user {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Enter your name: ");

String name = [Link]();

[Link]("Enter your age: ");

int age = [Link]();

[Link]("Hello, " + name + "! You are " + age + " years old.");

[Link]();

OUTPUT:-
[Link] a java program to find factorial using for loop.

public class factorial

public static void main(String[] args)

int num = 5;

long factorial = 1;

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

factorial *= i;

[Link]("Factorial of " + num + " is: " + factorial);

OUTPUT:-
[Link] a java program to access Array.

public class arr

public static void main(String[] args)

int[] age={52,45,14};

[Link]("first element= " +age[0]);

[Link]("second element= " +age[1]);

[Link]("third element= " +age[2]);

OUTPUT:-
[Link] a java program to accept number from user and check whether number is even
or odd.

import [Link];

public class EvenOddCheck {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Enter a number: ");

int number = [Link]();

if (number % 2 == 0) {

[Link](number + " is an even number.");

} else {

[Link](number + " is an odd number.");

[Link]();

OUTPUT:-
[Link] a java program to to check wheather number is prime or not.

import [Link];
public class PrimeCheck
{
public static void main(String[] args)
{
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
if (isPrime(number))
{
[Link](number + " is a prime number.");
}
Else
{
[Link](number + " is not a prime number.");
}
[Link]();
}
public static boolean isPrime(int num)
{
if (num <= 1)
{
return false;
}
for (int i = 2; i <= [Link](num); i++)
{
if (num % i == 0) {
return false;
}
}
return true;
}
}
OUTPUT:-
[Link] a java program to display alphabet using for loop.

public class alpha

public static void main(String[ ] args)

char c;

for(c='A';c<='Z';++c)

[Link](c+" ");

OUTPUT:-

You might also like