SlideShare a Scribd company logo
1 of 12
Some Examples And Things To Remember
C++ And Java
Programe to interchange the
values of two variables
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int num,num1,replace;

 cout<<"entre number 1"<<endl;
 cin>>num;
 cout<<"entre number 2"<<endl;
 cin>>num1;
 replace=num;
 num=num1;
 num1=replace;
 cout<<"after replacing
"<<endl<<num<<endl;
 cout<<"after replacing "<<endl<<num1;
 }
 public static void main(String[] args) {
 int num,num1,replace;
 Scanner a=new Scanner(System.in);
 System.out.println("entre number 1");
 num=a.nextInt();
 System.out.println("entre number 2");
 num1=a.nextInt();
 replace=num;
 num=num1;
 num1=replace;
 System.out.println("after replacing
"+num);
 System.out.println("after replacing
"+num1);



 }

Programe to find absolute of a
negative number(Without if else)
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int num,num1,replace;

 cout<<"entre negative number
"<<endl;
 cin>>num;
 int abs=num*-1;

 cout<<"abs value is
"<<endl<<abs<<endl;

 }
 public static void main(String[] args) {
 int num;
 Scanner a=new
Scanner(System.in);
 System.out.println("entre
negative number");
 num=a.nextInt();
 int abs=num*-1;
 System.out.println("absolute
value is "+abs);




 }
User entered 3 digit number break
it in single digits and display
accordingly
In c++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int num,bre,bre1,bre2,b,c;

 cout<<"entre 3 digit number "<<endl;
 cin>>num;
 bre=num/100;
 c=num/10;
 bre1=c%10;
 bre2=num%10;

 cout<<"first digit is "<<endl<<bre<<endl;
 cout<<"Second digit is "<<endl<<bre1<<endl;
 cout<<"third digit is "<<endl<<bre2<<endl;

 }
 public static void main(String[] args) {
 // TODO code application logic here
 int number,bre,bre1,bre2,b,c;
 Scanner a =new Scanner(System.in);
 System.out.println("entre 3 digit
number");
 number=a.nextInt();
 bre=number/100;
 c=number/10;
 bre1=c%10;
 bre2=number%10;
 System.out.println("first digit is "+bre);
 System.out.println("second digit is
"+bre1);
 System.out.println("third digit is
"+bre2);

 }
Difference between / and %
Division / Modulus %
 4/2 will give 2
 10/5 will give 2
 15/3 will give 3
 21/2 will give 10
 4%2 will give 0
 10%2 will give 0
 15/3 will give 0
 21/2 will give 5
 Help full tool used to break
the number in single digits
Marks entered by user find average
of these marks
In c++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int num,num1,num2;

 cout<<"entre marks of sub1 "<<endl;
 cin>>num;
 cout<<"entre marks of sub2 "<<endl;
 cin>>num1;
 cout<<"entre marks of sub3 "<<endl;
 cin>>num2;
 int avg=(num+num1+num2)/3;

 cout<<"avg is "<<endl<<avg<<endl;


 }
 public class JavaApplication10 {
 /**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
 // TODO code application logic here
 int number,number1,number2;
 Scanner a =new Scanner(System.in);
 System.out.println("entre marks of sub 1");
 number=a.nextInt();
 System.out.println("entre marks of sub 2");
 number1=a.nextInt();
 System.out.println("entre marks of sub 3");
 number2=a.nextInt();
 int avg=(number+number1+number2)/3;

 System.out.println("avarage is "+avg);

 }

 }
Temperature in fahrenheit is input
convert it into celsius
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 float far,cel;

 cout<<"entre temperature in farenhet
"<<endl;
 cin>>far;

 cel=(far-32)*5/9;

 cout<<"temp in celseius is
"<<endl<<cel<<endl;


 }
 */
 public class JavaApplication10 {
 /**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
 // TODO code application logic here
 double far,cel;
 Scanner a =new Scanner(System.in);
 System.out.println("entre temparature in
farenheit ");
 far=a.nextDouble();
 cel=(far-32)*5/9;
 System.out.println("Temp in cel is "+cel+"degree
celcius");

 }

 }
Ayaz basic salary is input through the keyboard. His dearness
allowance is 40% of basic salary, and house rent allowance is 20%
of basic salary. Write a program to calculate his gross salary.
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 float bsal,da,hr,gsal;

 cout<<"entre basic salary "<<endl;
 cin>>bsal;
 da=0.4*bsal;
 hr=0.2*bsal;
 gsal=bsal-da-hr;
 cout<<"Gross salar is
"<<endl<<gsal<<endl;


 }
 public class JavaApplication10 {
 /**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
 // TODO code application logic here
 double bsal,da,hr,gsal;
 Scanner a =new Scanner(System.in);
 System.out.println("Ayaz entre your basic
salary ");
 bsal=a.nextInt();
 da=0.4*bsal;
 hr=0.2*bsal;
 gsal=bsal-da-hr;
 System.out.println("gross salary is"+gsal);

 }

 }
If a three-digit number is input through the keyboard, write a program to print
a new number by adding one to each of its digits. For example if the number
that is input is 123 then the output should be displayed as 234.
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int number,bre,bre1,bre2,b,c,nbre,nbre1,nbre2;
 cout<<"entre number"<<endl;
 cin>>number;
 bre=number/100;
 nbre=bre+1;
 c=number/10;
 bre1=c%10;
 nbre1=bre1+1;
 bre2=number%10;
 nbre2=bre2+1;
 cout<<"after adding 1 is"<<endl;
 cout<<nbre;
 cout<<nbre1;
 cout<<nbre2;

 }
 int
number,bre,bre1,bre2,b,c,nbre,nbre1,nbre2;
 Scanner a =new Scanner(System.in);
 number=a.nextInt();
 bre=number/100;
 nbre=bre+1;
 c=number/10;
 bre1=c%10;
 nbre1=bre1+1;
 bre2=number%10;
 nbre2=bre2+1;
 System.out.println("after adding 1 is");
 System.out.print(nbre);
 System.out.print(nbre1);
 System.out.print(nbre2);
Radius is input from user find area
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 float radius,area;
 cout<<"entre radius"<<endl;
 cin>>radius;
 area=3.14*radius*radius;
 cout<<"radius is"<<endl;
 cout<<area;


 }
 public class JavaApplication10 {
 /**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
 // TODO code application logic here
 double radius,area;
 Scanner a =new Scanner(System.in);
 System.out.println("entre radius");
 radius=a.nextDouble();
 area=3.14*radius*radius;
 System.out.println("area is"+area);


 }

 }
Key points
In C++ In Java
 In order to give one line gap we
use endl
 In C++ endl will give the one
line gap and cursor will go to
next line
 cout<<"entre radius"<<endl;
 In above instruction entre ra
dius will print and <<endl will
provide the one line gap
 Join string with variable we use
string << variablename;
 In order to give one line gap
we use System.out.println
 Here ln will give one line
break if we use
System.out.print it do not
give one line break and print
in the same line
 If we want to join string with
variable value we use + sign
Thanks alot
Contact me at
muhammadhaseeb562@gmai
l.com
Mobile no:-
0336-5686312

More Related Content

What's hot

What's hot (20)

Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency API
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
Python
PythonPython
Python
 
c programming
c programmingc programming
c programming
 
C++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingC++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogramming
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
C++11
C++11C++11
C++11
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
 
Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
Operating System Assignment Help
Operating System Assignment HelpOperating System Assignment Help
Operating System Assignment Help
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
Ee 3122 numerical methods and statistics sessional credit
Ee 3122 numerical methods and statistics sessional  creditEe 3122 numerical methods and statistics sessional  credit
Ee 3122 numerical methods and statistics sessional credit
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
 
functions
functionsfunctions
functions
 

Viewers also liked

Understanding Mobile Consumer - Singapore
Understanding Mobile Consumer - SingaporeUnderstanding Mobile Consumer - Singapore
Understanding Mobile Consumer - SingaporeVijay Chander
 
Civic Service, A Tale of 3 Paradigms, w notes 2015 Sept 21
Civic Service, A Tale of 3 Paradigms, w notes    2015 Sept 21  Civic Service, A Tale of 3 Paradigms, w notes    2015 Sept 21
Civic Service, A Tale of 3 Paradigms, w notes 2015 Sept 21 Robert Terry
 
Educacion comunicativa eric r
Educacion comunicativa eric rEducacion comunicativa eric r
Educacion comunicativa eric rAlbin Bas
 
1ª corrida da proteção civil bvcs final
1ª corrida da proteção civil bvcs final1ª corrida da proteção civil bvcs final
1ª corrida da proteção civil bvcs finalbvcsal
 
Conflict in Sri Lanka
Conflict in Sri LankaConflict in Sri Lanka
Conflict in Sri LankaAishaAziz
 
Are You Low On Magnesium?
Are You Low On Magnesium?Are You Low On Magnesium?
Are You Low On Magnesium?Katie Wells
 
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...ehsan sepahi
 
Mary T Bogen Resume 2015-1
Mary T Bogen Resume 2015-1Mary T Bogen Resume 2015-1
Mary T Bogen Resume 2015-1Mary Bogen
 
A study on the problems faced by the social science teachers in the high scho...
A study on the problems faced by the social science teachers in the high scho...A study on the problems faced by the social science teachers in the high scho...
A study on the problems faced by the social science teachers in the high scho...remyabalan78
 
Apuntes la vida_en_la_prehistoria
Apuntes la vida_en_la_prehistoriaApuntes la vida_en_la_prehistoria
Apuntes la vida_en_la_prehistoriasergio.historia
 
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2Weng Lun Ho
 
Chapter 13 political transformations : Empires and encounters 1450-1750
Chapter 13 political transformations : Empires and encounters 1450-1750Chapter 13 political transformations : Empires and encounters 1450-1750
Chapter 13 political transformations : Empires and encounters 1450-1750S Sandoval
 

Viewers also liked (20)

SU-030 Enrolling Users
SU-030 Enrolling UsersSU-030 Enrolling Users
SU-030 Enrolling Users
 
Study Review
Study ReviewStudy Review
Study Review
 
As
AsAs
As
 
Understanding Mobile Consumer - Singapore
Understanding Mobile Consumer - SingaporeUnderstanding Mobile Consumer - Singapore
Understanding Mobile Consumer - Singapore
 
Civic Service, A Tale of 3 Paradigms, w notes 2015 Sept 21
Civic Service, A Tale of 3 Paradigms, w notes    2015 Sept 21  Civic Service, A Tale of 3 Paradigms, w notes    2015 Sept 21
Civic Service, A Tale of 3 Paradigms, w notes 2015 Sept 21
 
Membuat otline
Membuat otlineMembuat otline
Membuat otline
 
Educacion comunicativa eric r
Educacion comunicativa eric rEducacion comunicativa eric r
Educacion comunicativa eric r
 
The laundry railway
The  laundry railwayThe  laundry railway
The laundry railway
 
1ª corrida da proteção civil bvcs final
1ª corrida da proteção civil bvcs final1ª corrida da proteção civil bvcs final
1ª corrida da proteção civil bvcs final
 
Conflict in Sri Lanka
Conflict in Sri LankaConflict in Sri Lanka
Conflict in Sri Lanka
 
Resume CA Avisha Vohra
Resume CA Avisha VohraResume CA Avisha Vohra
Resume CA Avisha Vohra
 
Métricas de Similaridade de Imagens
Métricas de Similaridade de ImagensMétricas de Similaridade de Imagens
Métricas de Similaridade de Imagens
 
Are You Low On Magnesium?
Are You Low On Magnesium?Are You Low On Magnesium?
Are You Low On Magnesium?
 
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
 
AP WH Chapter 12 PPT
AP WH Chapter 12 PPTAP WH Chapter 12 PPT
AP WH Chapter 12 PPT
 
Mary T Bogen Resume 2015-1
Mary T Bogen Resume 2015-1Mary T Bogen Resume 2015-1
Mary T Bogen Resume 2015-1
 
A study on the problems faced by the social science teachers in the high scho...
A study on the problems faced by the social science teachers in the high scho...A study on the problems faced by the social science teachers in the high scho...
A study on the problems faced by the social science teachers in the high scho...
 
Apuntes la vida_en_la_prehistoria
Apuntes la vida_en_la_prehistoriaApuntes la vida_en_la_prehistoria
Apuntes la vida_en_la_prehistoria
 
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
 
Chapter 13 political transformations : Empires and encounters 1450-1750
Chapter 13 political transformations : Empires and encounters 1450-1750Chapter 13 political transformations : Empires and encounters 1450-1750
Chapter 13 political transformations : Empires and encounters 1450-1750
 

Similar to Lecture no 3

Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfmallik3000
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101premrings
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsMorteza Mahdilar
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaonyash production
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 

Similar to Lecture no 3 (20)

Base de-datos
Base de-datosBase de-datos
Base de-datos
 
Computer Programming- Lecture 7
Computer Programming- Lecture 7Computer Programming- Lecture 7
Computer Programming- Lecture 7
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Pointer
PointerPointer
Pointer
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditions
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
C++
C++C++
C++
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
 
901131 examples
901131 examples901131 examples
901131 examples
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
C++ Programs
C++ ProgramsC++ Programs
C++ Programs
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

Lecture no 3

  • 1. Some Examples And Things To Remember C++ And Java
  • 2. Programe to interchange the values of two variables In C++ In Java  #include<iostream>  using namespace std;  int main()  {  int num,num1,replace;   cout<<"entre number 1"<<endl;  cin>>num;  cout<<"entre number 2"<<endl;  cin>>num1;  replace=num;  num=num1;  num1=replace;  cout<<"after replacing "<<endl<<num<<endl;  cout<<"after replacing "<<endl<<num1;  }  public static void main(String[] args) {  int num,num1,replace;  Scanner a=new Scanner(System.in);  System.out.println("entre number 1");  num=a.nextInt();  System.out.println("entre number 2");  num1=a.nextInt();  replace=num;  num=num1;  num1=replace;  System.out.println("after replacing "+num);  System.out.println("after replacing "+num1);     } 
  • 3. Programe to find absolute of a negative number(Without if else) In C++ In Java  #include<iostream>  using namespace std;  int main()  {  int num,num1,replace;   cout<<"entre negative number "<<endl;  cin>>num;  int abs=num*-1;   cout<<"abs value is "<<endl<<abs<<endl;   }  public static void main(String[] args) {  int num;  Scanner a=new Scanner(System.in);  System.out.println("entre negative number");  num=a.nextInt();  int abs=num*-1;  System.out.println("absolute value is "+abs);      }
  • 4. User entered 3 digit number break it in single digits and display accordingly In c++ In Java  #include<iostream>  using namespace std;  int main()  {  int num,bre,bre1,bre2,b,c;   cout<<"entre 3 digit number "<<endl;  cin>>num;  bre=num/100;  c=num/10;  bre1=c%10;  bre2=num%10;   cout<<"first digit is "<<endl<<bre<<endl;  cout<<"Second digit is "<<endl<<bre1<<endl;  cout<<"third digit is "<<endl<<bre2<<endl;   }  public static void main(String[] args) {  // TODO code application logic here  int number,bre,bre1,bre2,b,c;  Scanner a =new Scanner(System.in);  System.out.println("entre 3 digit number");  number=a.nextInt();  bre=number/100;  c=number/10;  bre1=c%10;  bre2=number%10;  System.out.println("first digit is "+bre);  System.out.println("second digit is "+bre1);  System.out.println("third digit is "+bre2);   }
  • 5. Difference between / and % Division / Modulus %  4/2 will give 2  10/5 will give 2  15/3 will give 3  21/2 will give 10  4%2 will give 0  10%2 will give 0  15/3 will give 0  21/2 will give 5  Help full tool used to break the number in single digits
  • 6. Marks entered by user find average of these marks In c++ In Java  #include<iostream>  using namespace std;  int main()  {  int num,num1,num2;   cout<<"entre marks of sub1 "<<endl;  cin>>num;  cout<<"entre marks of sub2 "<<endl;  cin>>num1;  cout<<"entre marks of sub3 "<<endl;  cin>>num2;  int avg=(num+num1+num2)/3;   cout<<"avg is "<<endl<<avg<<endl;    }  public class JavaApplication10 {  /**  * @param args the command line arguments  */  public static void main(String[] args) {  // TODO code application logic here  int number,number1,number2;  Scanner a =new Scanner(System.in);  System.out.println("entre marks of sub 1");  number=a.nextInt();  System.out.println("entre marks of sub 2");  number1=a.nextInt();  System.out.println("entre marks of sub 3");  number2=a.nextInt();  int avg=(number+number1+number2)/3;   System.out.println("avarage is "+avg);   }   }
  • 7. Temperature in fahrenheit is input convert it into celsius In C++ In Java  #include<iostream>  using namespace std;  int main()  {  float far,cel;   cout<<"entre temperature in farenhet "<<endl;  cin>>far;   cel=(far-32)*5/9;   cout<<"temp in celseius is "<<endl<<cel<<endl;    }  */  public class JavaApplication10 {  /**  * @param args the command line arguments  */  public static void main(String[] args) {  // TODO code application logic here  double far,cel;  Scanner a =new Scanner(System.in);  System.out.println("entre temparature in farenheit ");  far=a.nextDouble();  cel=(far-32)*5/9;  System.out.println("Temp in cel is "+cel+"degree celcius");   }   }
  • 8. Ayaz basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary. In C++ In Java  #include<iostream>  using namespace std;  int main()  {  float bsal,da,hr,gsal;   cout<<"entre basic salary "<<endl;  cin>>bsal;  da=0.4*bsal;  hr=0.2*bsal;  gsal=bsal-da-hr;  cout<<"Gross salar is "<<endl<<gsal<<endl;    }  public class JavaApplication10 {  /**  * @param args the command line arguments  */  public static void main(String[] args) {  // TODO code application logic here  double bsal,da,hr,gsal;  Scanner a =new Scanner(System.in);  System.out.println("Ayaz entre your basic salary ");  bsal=a.nextInt();  da=0.4*bsal;  hr=0.2*bsal;  gsal=bsal-da-hr;  System.out.println("gross salary is"+gsal);   }   }
  • 9. If a three-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 123 then the output should be displayed as 234. In C++ In Java  #include<iostream>  using namespace std;  int main()  {  int number,bre,bre1,bre2,b,c,nbre,nbre1,nbre2;  cout<<"entre number"<<endl;  cin>>number;  bre=number/100;  nbre=bre+1;  c=number/10;  bre1=c%10;  nbre1=bre1+1;  bre2=number%10;  nbre2=bre2+1;  cout<<"after adding 1 is"<<endl;  cout<<nbre;  cout<<nbre1;  cout<<nbre2;   }  int number,bre,bre1,bre2,b,c,nbre,nbre1,nbre2;  Scanner a =new Scanner(System.in);  number=a.nextInt();  bre=number/100;  nbre=bre+1;  c=number/10;  bre1=c%10;  nbre1=bre1+1;  bre2=number%10;  nbre2=bre2+1;  System.out.println("after adding 1 is");  System.out.print(nbre);  System.out.print(nbre1);  System.out.print(nbre2);
  • 10. Radius is input from user find area In C++ In Java  #include<iostream>  using namespace std;  int main()  {  float radius,area;  cout<<"entre radius"<<endl;  cin>>radius;  area=3.14*radius*radius;  cout<<"radius is"<<endl;  cout<<area;    }  public class JavaApplication10 {  /**  * @param args the command line arguments  */  public static void main(String[] args) {  // TODO code application logic here  double radius,area;  Scanner a =new Scanner(System.in);  System.out.println("entre radius");  radius=a.nextDouble();  area=3.14*radius*radius;  System.out.println("area is"+area);    }   }
  • 11. Key points In C++ In Java  In order to give one line gap we use endl  In C++ endl will give the one line gap and cursor will go to next line  cout<<"entre radius"<<endl;  In above instruction entre ra dius will print and <<endl will provide the one line gap  Join string with variable we use string << variablename;  In order to give one line gap we use System.out.println  Here ln will give one line break if we use System.out.print it do not give one line break and print in the same line  If we want to join string with variable value we use + sign
  • 12. Thanks alot Contact me at muhammadhaseeb562@gmai l.com Mobile no:- 0336-5686312