This document contains Java code snippets for various mathematical and logical programs, including programs to:
- Add, subtract, multiply, and divide two numbers
- Check if a number is even or odd
- Find the factorial of a number recursively and using a while loop
- Determine if a number is prime
- Calculate the roots of a quadratic equation
- Convert a binary number to decimal
The document provides over 20 code examples of common programming problems and their solutions in Java.
tracts
all function definitions that can be hoisted using dynamic
analysis framework Jalangi framework. This approach was evaluated
on the following JS Libraries: Q1, Underscore and Lodash.
The accuracy of this approach was 100%, 50%, and 100% respectively.
Keywords: Hoisting Functions - Nested Functions- Dynamic
Analysis.
In this report, we produce a dynamic analysis approach which extracts
all function definitions that can be hoisted using dynamic
analysis framework Jalangi framework. This approach was evaluated
on the following JS Libraries: Q1, Underscore and Lodash.
The accuracy of this approach was 100%, 50%, and 100% respectively.
Keywords: Hoisting Functions - Nested Functions- Dynamic
Analysis.
ppt of class and methods in java,recursion in java,nested class,java,command line argument,method overloading,call by value,call by reference,constructor overloading core java ppt
tracts
all function definitions that can be hoisted using dynamic
analysis framework Jalangi framework. This approach was evaluated
on the following JS Libraries: Q1, Underscore and Lodash.
The accuracy of this approach was 100%, 50%, and 100% respectively.
Keywords: Hoisting Functions - Nested Functions- Dynamic
Analysis.
In this report, we produce a dynamic analysis approach which extracts
all function definitions that can be hoisted using dynamic
analysis framework Jalangi framework. This approach was evaluated
on the following JS Libraries: Q1, Underscore and Lodash.
The accuracy of this approach was 100%, 50%, and 100% respectively.
Keywords: Hoisting Functions - Nested Functions- Dynamic
Analysis.
ppt of class and methods in java,recursion in java,nested class,java,command line argument,method overloading,call by value,call by reference,constructor overloading core java ppt
Avec plus de 2,2 Millions d’applications disponibles dans les stores en ce début d’année, le téléchargement d’une application est une problématique récurrente des projets applicatifs mobiles. Il est donc important de comprendre les mécanismes de téléchargement afin d’accompagner le lancement commercial de votre application.
Dans ce premier volet d’articles consacrés au téléchargement de votre application, nous aimerions partager avec vous la première étape de la mise en place d’une stratégie mobile performante: le référencement naturel.
L’App Store Optimization (ASO) est la première étape pour optimiser les téléchargements de votre application. Souvent négligé, l’ASO permet à votre application d’être trouvée plus facilement dans les store d’applications et par extension de générer des téléchargements supplémentaires.
L’ASO est considéré comme le SEO mobile dans les stores d’applications.
asiMOVE résume pour vous en infographie les facteurs clés qui influenceront le référencement naturel de votre application dans les stores dédiés.
**
ZOOM SUR LE RÉFÉRENCEMENT DE VOTRE APPLICATION
La recherche dans un store d’applications est la méthode la plus populaire pour découvrir des applications, le bouche à oreille occupant la deuxième marche du podium selon Forester.
Bon à savoir :
90% des applications sont gratuites
80% des applications sont téléchargées moins de 1’000x
40 apps installées par Smartphone en Suisse
Facteurs d’optimisation :
Nom de l’application : A moins d’avoir un nom de marque très fort, mieux vaut privilégier un nom d’application descriptif contenant le mot clé principal de votre activité
Qualité des images : Utilisez les captures d’écran pour démontrer les fonctionnalités de votre application. L’icône est une des premières choses que l’utilisateur remarquera
Description : Décrivez pourquoi votre application est unique dès la première phrase. Restez simple et allez à l’essentiel. Listez également les fonctionnalités
Mots clés : Associez votre contenu avec une variété de mots-clés relatifs à l'application elle-même, mais également avec votre cœur de métier
Engagement : Encouragez vos utilisateurs à donner leur avis et noter l’application. Le rating et les commentaires sont pris en compte
Code : Publiez une application de qualité. Les bugs ont un fort impact sur le taux de téléchargement et le rating des applications
Liens : Mettez à disposition des utilisateurs un url et une adresse email de support, un compte twitter... dans la description
Mises à jour : Effectuez des mises à jour régulières pour notifier vos utilisateurs. Utiliser la description courte pour continuer à vendre votre application
Communication : Provoquer des pics de téléchargements, notamment pour iOS. Préférez les canaux de communication dédiés au mobile
Code:
import java.util.Random;
import java.util.Scanner;
public class Test{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String bin = \"1\";
int n;
System.out.print(\"Enter the number of binary digits : \");
n = input.nextInt();
for(int i = 0; i < n-1; i++){
bin += randomBin();
}
System.out.println(bin);
}
public static String randomBin() {
Random rg = new Random();
int n = rg.nextInt(2);
return Integer.toBinaryString(n);
}
}
Output:
Enter the number of binary digits : 5
10110
Solution
Code:
import java.util.Random;
import java.util.Scanner;
public class Test{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String bin = \"1\";
int n;
System.out.print(\"Enter the number of binary digits : \");
n = input.nextInt();
for(int i = 0; i < n-1; i++){
bin += randomBin();
}
System.out.println(bin);
}
public static String randomBin() {
Random rg = new Random();
int n = rg.nextInt(2);
return Integer.toBinaryString(n);
}
}
Output:
Enter the number of binary digits : 5
10110.
Write a Java application that asks for an integer and returns its fac.pdfhadpadrrajeshh
Write a Java application that asks for an integer and returns its factorization into prime factors
including their powers. The prime factors must appear in increasing order. For example if 120 (=
2*2*2*3*5) in the input number, then your program should output 120 = 2^3 * 3^1 * 5^1 The
factors should appear in increasing order and should be separated from each other by asterisks
(*).
Solution
import java.util.Scanner;
public class factorialFactorization {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.print(\"Enter a number:\");
int n = scan.nextInt();
int fact=1;
for(int i=2;i<=n;i++)
{
fact = fact*i;
}
int count=0,hat=0;
System.out.print(fact);
System.out.print(\" = \");
for(int i=2;fact>1;i++)
{
count = 0;
while(true)
{
if(fact%i==0)
{
count++;
fact = fact/i;
}
else
{
break;
}
}
if(count>0)
{
if(hat>0)
{
System.out.print(\" * \");
}
System.out.print(i);
System.out.print(\"^\");
System.out.print(count);
hat ++;
}
}
}
}.
import java.util.;public class Program{public static void.pdfoptokunal1
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x=\"X\";
int amount;
System.out.println(\"Enter amount\");
amount=input.nextInt();
System.out.println(\"Amount is: \"+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X\'s twice? I am doing basic Java so please try to explain
using the most basic codes.
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x=\"X\";
int amount;
System.out.println(\"Enter amount\");
amount=input.nextInt();
System.out.println(\"Amount is: \"+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X\'s twice? I am doing basic Java so please try to explain
using the most basic codes.
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x=\"X\";
int amount;
System.out.println(\"Enter amount\");
amount=input.nextInt();
System.out.println(\"Amount is: \"+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X\'s twice? I am doing basic Java so please try to explain
using the most basic codes.
Solution
Hi,
I have modified the code. it is working as expected now. Highlighted the code changes below.
Issue here is with you have written this statement twice System.out.println(x); which causes the
issue.
Program.java
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x=\"X\";
int amount;
System.out.println(\"Enter amount\");
amount=input.nextInt();
System.out.println(\"Amount is: \"+amount);
for(int i=1; i<=amount; i++)
{
System.out.println();
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Output:
Enter amount
10
Amount is: 10
X
XX
XXX
XXXX
XXXXX
XXXXXX
XXXXXXX
XXXXXXXX
XXXXXXXXX
XXXXXXXXXX.
The sample program for above series in JAVA will be like belowimpo.pdfrajat630669
The sample program for above series in JAVA will be like below
import java.util.Scan;
public class PIVALUE {
public static void main(String[] args) {
// Scan object creation
Scan input = new Scan (System.in);
// ask user for input
System.out.println(\"Enter num.\");
double j = input.nextDouble(); // user entered value of j
double Tot = 0;
for(j=0; j<10000; j++){
if(j%2 == 0) // check remainder of `j/2` is 0
Tot += -1 / ( 2 * j - 1);
else
Tot += 1 / (2 * j - 1);
}
System.out.println(Tot);
}
}
Solution
The sample program for above series in JAVA will be like below
import java.util.Scan;
public class PIVALUE {
public static void main(String[] args) {
// Scan object creation
Scan input = new Scan (System.in);
// ask user for input
System.out.println(\"Enter num.\");
double j = input.nextDouble(); // user entered value of j
double Tot = 0;
for(j=0; j<10000; j++){
if(j%2 == 0) // check remainder of `j/2` is 0
Tot += -1 / ( 2 * j - 1);
else
Tot += 1 / (2 * j - 1);
}
System.out.println(Tot);
}
}.
The sample program for above series in JAVA will be like belowimpo.pdfrajat630669
The sample program for above series in JAVA will be like below
import java.util.Scan;
public class PIVALUE {
public static void main(String[] args) {
// Scan object creation
Scan input = new Scan (System.in);
// ask user for input
System.out.println(\"Enter num.\");
double j = input.nextDouble(); // user entered value of j
double Tot = 0;
for(j=0; j<10000; j++){
if(j%2 == 0) // check remainder of `j/2` is 0
Tot += -1 / ( 2 * j - 1);
else
Tot += 1 / (2 * j - 1);
}
System.out.println(Tot);
}
}
Solution
The sample program for above series in JAVA will be like below
import java.util.Scan;
public class PIVALUE {
public static void main(String[] args) {
// Scan object creation
Scan input = new Scan (System.in);
// ask user for input
System.out.println(\"Enter num.\");
double j = input.nextDouble(); // user entered value of j
double Tot = 0;
for(j=0; j<10000; j++){
if(j%2 == 0) // check remainder of `j/2` is 0
Tot += -1 / ( 2 * j - 1);
else
Tot += 1 / (2 * j - 1);
}
System.out.println(Tot);
}
}.
Factors.javaimport java.io.; import java.util.Scanner; class .pdfdeepakangel
Factors.java
import java.io.*;
import java.util.Scanner;
class Factors
{
public static void main(String args[])
{
int a,i;
Scanner in = new Scanner(System.in);
System.out.println(\"Enter an integer\");
a = in.nextInt();
System.out.println(\"You entered integer \"+a);
System.out.print(\"\ \");
System.out.print(\"The factors are : \");
for(i=1;i<=a/2;i++)
{
if(a%i==0)
System.out.print(i+\",\");
}
System.out.print(a);
}
}
Output:
Enter an integer
44
You entered integer 44
The factors are : 1,2,4,11,22,44
Solution
Factors.java
import java.io.*;
import java.util.Scanner;
class Factors
{
public static void main(String args[])
{
int a,i;
Scanner in = new Scanner(System.in);
System.out.println(\"Enter an integer\");
a = in.nextInt();
System.out.println(\"You entered integer \"+a);
System.out.print(\"\ \");
System.out.print(\"The factors are : \");
for(i=1;i<=a/2;i++)
{
if(a%i==0)
System.out.print(i+\",\");
}
System.out.print(a);
}
}
Output:
Enter an integer
44
You entered integer 44
The factors are : 1,2,4,11,22,44.
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfPeter Spielvogel
Building better applications for business users with SAP Fiori.
• What is SAP Fiori and why it matters to you
• How a better user experience drives measurable business benefits
• How to get started with SAP Fiori today
• How SAP Fiori elements accelerates application development
• How SAP Build Code includes SAP Fiori tools and other generative artificial intelligence capabilities
• How SAP Fiori paves the way for using AI in SAP apps
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™UiPathCommunity
In questo evento online gratuito, organizzato dalla Community Italiana di UiPath, potrai esplorare le nuove funzionalità di Autopilot, il tool che integra l'Intelligenza Artificiale nei processi di sviluppo e utilizzo delle Automazioni.
📕 Vedremo insieme alcuni esempi dell'utilizzo di Autopilot in diversi tool della Suite UiPath:
Autopilot per Studio Web
Autopilot per Studio
Autopilot per Apps
Clipboard AI
GenAI applicata alla Document Understanding
👨🏫👨💻 Speakers:
Stefano Negro, UiPath MVPx3, RPA Tech Lead @ BSP Consultant
Flavio Martinelli, UiPath MVP 2023, Technical Account Manager @UiPath
Andrei Tasca, RPA Solutions Team Lead @NTT Data
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Programs of java
1. Java Program for Addition of two
numbers
importjava.io.*;
importjava.lang.*;
classAddition
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("enter first number: ");
n1=Integer.parseInt(br.readLine());
System.out.println("enter second number: ");
n2=Integer.parseInt(br.readLine());
n1+=n2;
System.out.println("addition of two numbers is: "+n1);
}
}
Java Program for Subtraction of two
numbers
importjava.io.*;
importjava.lang.*;
classSub
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter first number: ");
n1=Integer.parseInt(br.readLine());
System.out.println("Enter second number: ");
n2=Integer.parseInt(br.readLine());
n1-=n2;
System.out.println("Subtraction of two given numbers is: "+n1);
}
}
2. Java Program for Multiplication of two
numbers
importjava.io.*;
importjava.lang.*;
classMul
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1=0,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter first number ");
n1=Integer.parseInt(br.readLine());
System.out.println("Enter second number ");
n2=Integer.parseInt(br.readLine());
n1*=n2; // or n1=n1*n2
System.out.println("Multiplication of two numbers is: "+n1);
}
}
3. Binary To Decimal Conversion
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
publicclassBinaryToDecimal
{
publicstaticvoidmain(String args[]) throwsException, IOException
{
intbin;
inti = 0;
intldigit=0;
intdcm=0;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.print("Enter Binary value: ");
bin=Integer.parseInt(br.readLine());
while(bin != 0)
{
ldigit = bin%10; //last digit of binary no
dcm = dcm+ldigit *((int) Math.pow(2,i));
i++;
bin = bin / 10; //removimg last digit from binary no
}
System.out.println("The decimal value for the given binary is:
"+dcm);
}
}
Solving Power Series
importjava.io.*;
classSeries2
{
publicstaticvoidmain(String args[]) throwsIOException
{
intn;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter n value: ");
n = Integer.parseInt(br.readLine());
if(n>0)
{
floatsum=0;
for(inti=1; i<=n; i++)
sum=sum+(float)(1)/(i*i);
System.out.println("Sum of Series:"+sum);
4. }
else
System.out.println("You Entered the Wrong no.");
}
}
Java Program to Find Frequency
Count of a Word in Given Text
importjava.io.*;
classFrequencyCount
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter the String: ");
String s=br.readLine();
System.out.println("Enter substring: ");
String sub=br.readLine();
intind,count=0;
for(inti=0; i+sub.length()<=s.length(); i++) //i+sub.length() is
used to reduce comparisions
{
ind=s.indexOf(sub,i);
if(ind>=0)
{
count++;
i=ind;
ind=-1;
}
}
System.out.println("Occurence of '"+sub+"' in String is "+count);
}
}
Java Program to Check Given String
is a POLYNDROME or Not
5. importjava.io.*;
importjava.lang.*;
classPolyndrome
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter the String: ");
String s=br.readLine();
String temp=s;
StringBuffersb= newStringBuffer(s);
sb.reverse();
s=sb.toString();
if(s.equals(temp))
System.out.print("String is polyndrome");
else
System.out.println("String is not polyndrome");
}
}
Java Program to Find Factorial of a
Given Number Using Recursion
importjava.io.*;
classFactorial
{
intfact(intn)
{
if(n<=1)
return1;
else
returnn*fact(n-1);
}
}
classRecursionFact
{
publicstaticvoidmain(String args[]) throwsIOException
{
intno;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter a Number: ");
no = Integer.parseInt(br.readLine());
if(no<0)
{
6. System.out.println("Negative number is not acceptable.");
}
else
{
Factorial f=newFactorial();
System.out.println("Factorial of "+no+" is: "+f.fact(no));
}
}
}
Java Program to Print Series
1,2,9,28,65
importjava.io.*;
classSeries
{
publicstaticvoidmain(String args[]) throwsIOException
{
intn;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter no.of elements in series: ");
n = Integer.parseInt(br.readLine());
if(n>0)
{
System.out.println("Series:");
for(inti=0; i<n; i++)
{
System.out.println("t"+(int)(Math.pow(i,3)+1)); //Pattern
for elements
}
}
else
System.out.println("You Entered the Wrong no.");
}
}
Java Program to Print Prime Numbers
With Less Comparisons
importjava.io.*;
9. System.out.println("t"+(int)(Math.pow(i,2)));
}
}
else
System.out.println("You Entered the Wrong no.");
}
}
Java Program to Find Given Number
Is Even or Odd
importjava.io.*;
importjava.lang.*;
classEvenOdd
{
publicstaticvoidmain(String args[])throwsIOException
{
intn=0;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter number: ");
n=Integer.parseInt(br.readLine());
n=n%2;
if(n==0)
System.out.println("The given number is even ");
else
System.out.println("The given number is odd ");
}
}
Java Program for Multiplication of two
numbers
importjava.io.*;
importjava.lang.*;
classMul
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1=0,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter first number ");
n1=Integer.parseInt(br.readLine());
System.out.println("Enter second number ");
n2=Integer.parseInt(br.readLine());
n1*=n2; // or n1=n1*n2
10. System.out.println("Multiplication of two numbers is: "+n1);
}
}
Java Program for Division of Two
Numbers
importjava.io.*;
importjava.lang.*;
classDiv
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1=0,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter first number: ");
n1=Integer.parseInt(br.readLine());
System.out.println("Enter second number: ");
n2=Integer.parseInt(br.readLine());
n1/=n2;
System.out.println("Division of two numbers is: "+n1);
}
}
Java Program for Addition of Two
Static Integer Numbers
importjava.io.*;
importjava.lang.*;
classStaticAdd
{
publicstaticvoidmain(String args[])
{
intn1=10,n2=20; //Static Defining of two Integer Variables
n1+=n2; // Performing Addition
System.out.println("Addition: "+n1);
}
}
Java Program for Multiplication of
Two Static Numbers
importjava.io.*;
importjava.lang.*;
classStaticMul
11. {
publicstaticvoidmain(String args[])
{
intn1=20,n2=10; //Defining Static Integer values
n1*=n2; // or n1=n1*n2;
System.out.println("Multiplicatation : "+n1);
}
}
Java Program to find Given Number is
Prime or Not
/* Write a Java program to Find whether number is Prime or Not. */
classPrimeNumber
{
publicstaticvoidmain(String args[])
{
intnumber = Integer.parseInt(args[0]);
intflag=0;
for(inti=2; i<number; i++)
{
if(number%i==0)
{
System.out.println(number+" is not a Prime Number");
flag = 1;
break;
}
}
if(flag==0)
System.out.println(number+" is a Prime Number");
}
}
Java Program to Find Whether Given
number is Armstrong or not
/*Write a program to find whether given no. is Armstrong or not.
Example :
Input - 153
Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */
classArmstrong
{
publicstaticvoidmain(String args[])
{<br> //Read Command Line Argument
intnum = Integer.parseInt(args[0]);
intn = num; //use to compare at If stmt
intcheck=0,remainder;
12. while(num> 0)
{
remainder = num % 10;
check = check + (int)Math.pow(remainder,3);
num = num / 10;
}
if(check == n)
System.out.println(n+" is an Armstrong Number");
else
System.out.println(n+" is not a Armstrong Number");
}
}
Java Program to Find Factorial of a
Given Number using While Loop
importjava.io.*;
importjava.lang.*;
classFactorial
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter Number: ");
intnum=Integer.parseInt(br.readLine());
intresult = 1;
while(num>0)
{
result = result * num;
num--;
}
System.out.println("Factorial of Given Number is : "+result);
}
}
Java Program to Find Maximum of
Two Numbers
classMaxoftwo
{
publicstaticvoidmain(String args[])
{
//taking value as command line argument.
//Converting String format to Integer value
13. inti = Integer.parseInt(args[0]);
intj = Integer.parseInt(args[1]);
if(i> j)
System.out.println(i+" is greater than "+j);
else
System.out.println(j+" is greater than "+i);
}
}
Java Program to Print Prime Numbers
up to Given Number
importjava.io.*;
importjava.lang.*;
classPrime
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter the value: ");
intn=Integer.parseInt(br.readLine());
System.out.println("Prime numbers are: ");
for(inti=1;i<=n;i++)
{
intp=0;
for(intj=1;j<=i;j++)
{
if(i%j==0)
p++;
}
if(p==2)
System.out.print(" "+i);
}
}
}
Java Program for Fibonacci Series
importjava.io.*;
importjava.lang.*;
classFibonacci
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));