SlideShare a Scribd company logo
1 of 2
Download to read offline
Code:
import java.util.*;
class Test{
public static void main(String args[])throws Exception{
Scanner input = new Scanner(System.in);
System.out.print("Enter the First Number : ");
int n1=input.nextInt();
System.out.print("Enter the Second Number : ");
int n2=input.nextInt();
System.out.println("GCD : "+gcd(n1,n2));
}
public static int gcd(int n1,int n2){
int r;
while(n2 != 0){
r = n1 % n2;
n1 = n2;
n2 = r;
}
return n1;
}
}
Output:
Enter the First Number : 54
Enter the Second Number : 24
GCD : 6
Solution
Code:
import java.util.*;
class Test{
public static void main(String args[])throws Exception{
Scanner input = new Scanner(System.in);
System.out.print("Enter the First Number : ");
int n1=input.nextInt();
System.out.print("Enter the Second Number : ");
int n2=input.nextInt();
System.out.println("GCD : "+gcd(n1,n2));
}
public static int gcd(int n1,int n2){
int r;
while(n2 != 0){
r = n1 % n2;
n1 = n2;
n2 = r;
}
return n1;
}
}
Output:
Enter the First Number : 54
Enter the Second Number : 24
GCD : 6

More Related Content

Similar to Codeimport java.util.; class Test{ public static void main(S.pdf

Modify before asshignment so that we can check input errors, etc.. P.pdf
Modify before asshignment so that we can check input errors, etc.. P.pdfModify before asshignment so that we can check input errors, etc.. P.pdf
Modify before asshignment so that we can check input errors, etc.. P.pdf
arihantplastictanksh
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
aquazac
 
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
apexelectronices01
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdf
anurag1231
 

Similar to Codeimport java.util.; class Test{ public static void main(S.pdf (12)

java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Oot practical
Oot practicalOot practical
Oot practical
 
Modify before asshignment so that we can check input errors, etc.. P.pdf
Modify before asshignment so that we can check input errors, etc.. P.pdfModify before asshignment so that we can check input errors, etc.. P.pdf
Modify before asshignment so that we can check input errors, etc.. P.pdf
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Two methods.pdf
Two methods.pdfTwo methods.pdf
Two methods.pdf
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
 
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdf
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 

More from anushasarees

Properties of enantiomers Their NMR and IR spec.pdf
                     Properties of enantiomers Their NMR and IR spec.pdf                     Properties of enantiomers Their NMR and IR spec.pdf
Properties of enantiomers Their NMR and IR spec.pdf
anushasarees
 
  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
anushasarees
 
There are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdfThere are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdf
anushasarees
 
The main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdfThe main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdf
anushasarees
 
Successfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdfSuccessfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdf
anushasarees
 
SolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdfSolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdf
anushasarees
 

More from anushasarees (20)

Properties of enantiomers Their NMR and IR spec.pdf
                     Properties of enantiomers Their NMR and IR spec.pdf                     Properties of enantiomers Their NMR and IR spec.pdf
Properties of enantiomers Their NMR and IR spec.pdf
 
O2 will be released as Na+ will not get reduce bu.pdf
                     O2 will be released as Na+ will not get reduce bu.pdf                     O2 will be released as Na+ will not get reduce bu.pdf
O2 will be released as Na+ will not get reduce bu.pdf
 
Huntingtons disease and other hereditary diseas.pdf
                     Huntingtons disease and other hereditary diseas.pdf                     Huntingtons disease and other hereditary diseas.pdf
Huntingtons disease and other hereditary diseas.pdf
 
ionic character BaF MgO FeO SO2 N2 .pdf
                     ionic character BaF  MgO  FeO  SO2  N2  .pdf                     ionic character BaF  MgO  FeO  SO2  N2  .pdf
ionic character BaF MgO FeO SO2 N2 .pdf
 
Nitrogen can hold up to 4 bonds. In sodium amide.pdf
                     Nitrogen can hold up to 4 bonds.  In sodium amide.pdf                     Nitrogen can hold up to 4 bonds.  In sodium amide.pdf
Nitrogen can hold up to 4 bonds. In sodium amide.pdf
 
C. hydrogen bonding. between N and H of differen.pdf
                     C. hydrogen bonding.  between N and H of differen.pdf                     C. hydrogen bonding.  between N and H of differen.pdf
C. hydrogen bonding. between N and H of differen.pdf
 
  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
 
We Know that    Amines are generally basic in naturebecause of th.pdf
We Know that    Amines are generally basic in naturebecause of th.pdfWe Know that    Amines are generally basic in naturebecause of th.pdf
We Know that    Amines are generally basic in naturebecause of th.pdf
 
There are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdfThere are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdf
 
Three are ways to protect unused switch ports Option B,D and E is.pdf
Three are ways to protect unused switch ports Option B,D and E is.pdfThree are ways to protect unused switch ports Option B,D and E is.pdf
Three are ways to protect unused switch ports Option B,D and E is.pdf
 
The water turns green because the copper(II)sulfate is breaking apar.pdf
The water turns green because the copper(II)sulfate is breaking apar.pdfThe water turns green because the copper(II)sulfate is breaking apar.pdf
The water turns green because the copper(II)sulfate is breaking apar.pdf
 
The mutation is known as inversion. In this a segment from one chrom.pdf
The mutation is known as inversion. In this a segment from one chrom.pdfThe mutation is known as inversion. In this a segment from one chrom.pdf
The mutation is known as inversion. In this a segment from one chrom.pdf
 
The main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdfThe main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdf
 
Successfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdfSuccessfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdf
 
SolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdfSolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdf
 
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdf
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdfSolutiona) Maximum bus speed = bus driver delay + propagation del.pdf
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdf
 
Solution Polymerase chain reaction is process in which several co.pdf
Solution Polymerase chain reaction is process in which several co.pdfSolution Polymerase chain reaction is process in which several co.pdf
Solution Polymerase chain reaction is process in which several co.pdf
 
Doubling [NO] would quadruple the rate .pdf
                     Doubling [NO] would quadruple the rate           .pdf                     Doubling [NO] would quadruple the rate           .pdf
Doubling [NO] would quadruple the rate .pdf
 
Correct answer F)4.0 .pdf
                     Correct answer F)4.0                            .pdf                     Correct answer F)4.0                            .pdf
Correct answer F)4.0 .pdf
 
D.) The system is neither at steady state or equi.pdf
                     D.) The system is neither at steady state or equi.pdf                     D.) The system is neither at steady state or equi.pdf
D.) The system is neither at steady state or equi.pdf
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 

Codeimport java.util.; class Test{ public static void main(S.pdf

  • 1. Code: import java.util.*; class Test{ public static void main(String args[])throws Exception{ Scanner input = new Scanner(System.in); System.out.print("Enter the First Number : "); int n1=input.nextInt(); System.out.print("Enter the Second Number : "); int n2=input.nextInt(); System.out.println("GCD : "+gcd(n1,n2)); } public static int gcd(int n1,int n2){ int r; while(n2 != 0){ r = n1 % n2; n1 = n2; n2 = r; } return n1; } } Output: Enter the First Number : 54 Enter the Second Number : 24 GCD : 6 Solution Code: import java.util.*; class Test{ public static void main(String args[])throws Exception{ Scanner input = new Scanner(System.in); System.out.print("Enter the First Number : "); int n1=input.nextInt();
  • 2. System.out.print("Enter the Second Number : "); int n2=input.nextInt(); System.out.println("GCD : "+gcd(n1,n2)); } public static int gcd(int n1,int n2){ int r; while(n2 != 0){ r = n1 % n2; n1 = n2; n2 = r; } return n1; } } Output: Enter the First Number : 54 Enter the Second Number : 24 GCD : 6