SlideShare a Scribd company logo
1 of 9
Download to read offline
// Problem1 java code
import java.util.Scanner;
// Java code to print all possible strings of letter L and R
class Problem1 {
static void print(char set[], int length) {
int setLength = set.length;
printRecursion(set, "", setLength, length);
}
static void printRecursion(char set[], String prefixset, int setLength, int length) {
// Base case: length is 0
if (length == 0) {
System.out.println(prefixset);
return;
}
for (int i = 0; i < setLength; ++i) {
String newPrefixset = prefixset + set[i];
printRecursion(set, newPrefixset, setLength, length - 1);
}
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter length: ");
int length = scan.nextInt();
char set[] = {'L', 'R'};
print(set, length);
}
}
/*
output:
Enter length:
3
LLL
LLR
LRL
LRR
RLL
RLR
RRL
RRR
*/
// Problem2 java code
import java.util.Scanner;
// Java code to print all possible strings of letter L and R
class Problem2 {
static void print(char set[], int length) {
int setLength = set.length;
printRecursion(set, "", setLength, length);
}
static void printRecursion(char set[], String prefixset, int setLength, int length) {
// Base case: length is 0
if (length == 0) {
System.out.print(prefixset + " ");
return;
}
for (int i = 0; i < setLength; ++i) {
String newPrefixset = prefixset + set[i];
printRecursion(set, newPrefixset, setLength, length - 1);
}
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter length: ");
int length = scan.nextInt();
char set[] = {'1', '3', '5', '7', '9'};
print(set, length);
System.out.println();
}
}
/*
output:
Enter length:
3
111 113 115 117 119 131 133 135 137 139 151 153 155
157 159 171 173 175 177 179 191 193 195 197 199 311
313 315 317 319 331 333 335 337 339 351 353 355 357
359 371 373 375 377 379 391 393 395 397 399 511 513
515 517 519 531 533 535 537 539 551 553 555 557 559
571 573 575 577 579 591 593 595 597 599 711 713 715
717 719 731 733 735 737 739 751 753 755 757 759 771
773 775 777 779 791 793 795 797 799 911 913 915 917
919 931 933 935 937 939 951 953 955 957 959 971 973
975 977 979 991 993 995 997 999
*/
// Problem3 java code
import java.util.Scanner;
// Java code to multiply 2 numbers
class Problem3 {
public static int multiply(int a, int b)
{
int temp = b;
for (int i = 1; i < a; i++ ) {
b = b + temp;
}
return b;
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter a: ");
int a = scan.nextInt();
System.out.println("Enter b: ");
int b = scan.nextInt();
System.out.println(a + "X" + b + " = " + multiply(a,b));
}
}
/*
output:
Enter a:
7
Enter b:
6
7X6 = 42
*/
// Problem4 java code
import java.util.Scanner;
// Java code to find gcd 2 numbers
class Problem4 {
public static int gcd(int a, int b)
{
if (b!=0)
return gcd(b, a%b);
else
return a;
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter a: ");
int a = scan.nextInt();
System.out.println("Enter b: ");
int b = scan.nextInt();
System.out.println("gcd(" + a + "," + b + ") = " + gcd(a,b));
}
}
/*
output:
Enter a:
10
Enter b:
12
gcd(10,12) = 2
*/
Solution
// Problem1 java code
import java.util.Scanner;
// Java code to print all possible strings of letter L and R
class Problem1 {
static void print(char set[], int length) {
int setLength = set.length;
printRecursion(set, "", setLength, length);
}
static void printRecursion(char set[], String prefixset, int setLength, int length) {
// Base case: length is 0
if (length == 0) {
System.out.println(prefixset);
return;
}
for (int i = 0; i < setLength; ++i) {
String newPrefixset = prefixset + set[i];
printRecursion(set, newPrefixset, setLength, length - 1);
}
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter length: ");
int length = scan.nextInt();
char set[] = {'L', 'R'};
print(set, length);
}
}
/*
output:
Enter length:
3
LLL
LLR
LRL
LRR
RLL
RLR
RRL
RRR
*/
// Problem2 java code
import java.util.Scanner;
// Java code to print all possible strings of letter L and R
class Problem2 {
static void print(char set[], int length) {
int setLength = set.length;
printRecursion(set, "", setLength, length);
}
static void printRecursion(char set[], String prefixset, int setLength, int length) {
// Base case: length is 0
if (length == 0) {
System.out.print(prefixset + " ");
return;
}
for (int i = 0; i < setLength; ++i) {
String newPrefixset = prefixset + set[i];
printRecursion(set, newPrefixset, setLength, length - 1);
}
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter length: ");
int length = scan.nextInt();
char set[] = {'1', '3', '5', '7', '9'};
print(set, length);
System.out.println();
}
}
/*
output:
Enter length:
3
111 113 115 117 119 131 133 135 137 139 151 153 155
157 159 171 173 175 177 179 191 193 195 197 199 311
313 315 317 319 331 333 335 337 339 351 353 355 357
359 371 373 375 377 379 391 393 395 397 399 511 513
515 517 519 531 533 535 537 539 551 553 555 557 559
571 573 575 577 579 591 593 595 597 599 711 713 715
717 719 731 733 735 737 739 751 753 755 757 759 771
773 775 777 779 791 793 795 797 799 911 913 915 917
919 931 933 935 937 939 951 953 955 957 959 971 973
975 977 979 991 993 995 997 999
*/
// Problem3 java code
import java.util.Scanner;
// Java code to multiply 2 numbers
class Problem3 {
public static int multiply(int a, int b)
{
int temp = b;
for (int i = 1; i < a; i++ ) {
b = b + temp;
}
return b;
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter a: ");
int a = scan.nextInt();
System.out.println("Enter b: ");
int b = scan.nextInt();
System.out.println(a + "X" + b + " = " + multiply(a,b));
}
}
/*
output:
Enter a:
7
Enter b:
6
7X6 = 42
*/
// Problem4 java code
import java.util.Scanner;
// Java code to find gcd 2 numbers
class Problem4 {
public static int gcd(int a, int b)
{
if (b!=0)
return gcd(b, a%b);
else
return a;
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter a: ");
int a = scan.nextInt();
System.out.println("Enter b: ");
int b = scan.nextInt();
System.out.println("gcd(" + a + "," + b + ") = " + gcd(a,b));
}
}
/*
output:
Enter a:
10
Enter b:
12
gcd(10,12) = 2
*/

More Related Content

Similar to Problem1 java codeimport java.util.Scanner; Java code to pr.pdf

Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iiiNiraj Bharambe
 
Demonstrating bully algorithm in java
Demonstrating bully algorithm in javaDemonstrating bully algorithm in java
Demonstrating bully algorithm in javaNagireddy Dwarampudi
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginnersishan0019
 
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfCountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfpremsrivastva8
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaanwalia Shaan
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfanurag1231
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfanjanacottonmills
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docxKatecate1
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfeyewatchsystems
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...MaruMengesha
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...Nithin Kumar,VVCE, Mysuru
 
An input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxAn input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxlauracallander
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming AssignmentCoding Assignment Help
 

Similar to Problem1 java codeimport java.util.Scanner; Java code to pr.pdf (20)

JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
 
STS4022 Exceptional_Handling
STS4022  Exceptional_HandlingSTS4022  Exceptional_Handling
STS4022 Exceptional_Handling
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iii
 
Demonstrating bully algorithm in java
Demonstrating bully algorithm in javaDemonstrating bully algorithm in java
Demonstrating bully algorithm in java
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfCountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdf
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 
Java final lab
Java final labJava final lab
Java final lab
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
 
An input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxAn input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docx
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 

More from anupamfootwear

All of the aboveSolution All of the above.pdf
 All of the aboveSolution All of the above.pdf All of the aboveSolution All of the above.pdf
All of the aboveSolution All of the above.pdfanupamfootwear
 
Yields a colorless solution and a white precipita.pdf
                     Yields a colorless solution and a white precipita.pdf                     Yields a colorless solution and a white precipita.pdf
Yields a colorless solution and a white precipita.pdfanupamfootwear
 
ROund to one significant figures, THen, its 2..pdf
                     ROund to one significant figures,  THen, its 2..pdf                     ROund to one significant figures,  THen, its 2..pdf
ROund to one significant figures, THen, its 2..pdfanupamfootwear
 
P=7.7(0.92)^t growth rate is dPdt differentiate .pdf
                     P=7.7(0.92)^t growth rate is dPdt differentiate .pdf                     P=7.7(0.92)^t growth rate is dPdt differentiate .pdf
P=7.7(0.92)^t growth rate is dPdt differentiate .pdfanupamfootwear
 
option (D) ... reason posted in my previous answe.pdf
                     option (D) ... reason posted in my previous answe.pdf                     option (D) ... reason posted in my previous answe.pdf
option (D) ... reason posted in my previous answe.pdfanupamfootwear
 
no.of moles of H2moles=28.82=14.4moles no.of mol.pdf
                     no.of moles of H2moles=28.82=14.4moles no.of mol.pdf                     no.of moles of H2moles=28.82=14.4moles no.of mol.pdf
no.of moles of H2moles=28.82=14.4moles no.of mol.pdfanupamfootwear
 
Ionic Compounds Think of an ionic compound as a .pdf
                     Ionic Compounds Think of an ionic compound as a .pdf                     Ionic Compounds Think of an ionic compound as a .pdf
Ionic Compounds Think of an ionic compound as a .pdfanupamfootwear
 
In the First molecule there will be Resonance whi.pdf
                     In the First molecule there will be Resonance whi.pdf                     In the First molecule there will be Resonance whi.pdf
In the First molecule there will be Resonance whi.pdfanupamfootwear
 
He down the group, IE decreases. Solution.pdf
                     He   down the group, IE decreases.   Solution.pdf                     He   down the group, IE decreases.   Solution.pdf
He down the group, IE decreases. Solution.pdfanupamfootwear
 
Uncouple agents will never disrupt the electron transport (they will.pdf
Uncouple agents will never disrupt the electron transport (they will.pdfUncouple agents will never disrupt the electron transport (they will.pdf
Uncouple agents will never disrupt the electron transport (they will.pdfanupamfootwear
 
The N and O atoms are both sp2 hybridized.The sp2 hybrid orbitals .pdf
The N and O atoms are both sp2 hybridized.The sp2 hybrid orbitals .pdfThe N and O atoms are both sp2 hybridized.The sp2 hybrid orbitals .pdf
The N and O atoms are both sp2 hybridized.The sp2 hybrid orbitals .pdfanupamfootwear
 
d.Addition of sulfuric acid to copper(II) oxide p.pdf
                     d.Addition of sulfuric acid to copper(II) oxide p.pdf                     d.Addition of sulfuric acid to copper(II) oxide p.pdf
d.Addition of sulfuric acid to copper(II) oxide p.pdfanupamfootwear
 
The 2nd statement and 3rd statement follow the seed and soil theory .pdf
The 2nd statement and 3rd statement follow the seed and soil theory .pdfThe 2nd statement and 3rd statement follow the seed and soil theory .pdf
The 2nd statement and 3rd statement follow the seed and soil theory .pdfanupamfootwear
 
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdfQuicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdfanupamfootwear
 
Pictures are not legible, could you plz post it again.Solution.pdf
Pictures are not legible, could you plz post it again.Solution.pdfPictures are not legible, could you plz post it again.Solution.pdf
Pictures are not legible, could you plz post it again.Solution.pdfanupamfootwear
 
Carbonic acid leaves the soda solution as CO2 (ca.pdf
                     Carbonic acid leaves the soda solution as CO2 (ca.pdf                     Carbonic acid leaves the soda solution as CO2 (ca.pdf
Carbonic acid leaves the soda solution as CO2 (ca.pdfanupamfootwear
 
mass= density volume= 2.330.10.10.01 = 2.3310-4gmsatomic .pdf
mass= density volume= 2.330.10.10.01 = 2.3310-4gmsatomic .pdfmass= density volume= 2.330.10.10.01 = 2.3310-4gmsatomic .pdf
mass= density volume= 2.330.10.10.01 = 2.3310-4gmsatomic .pdfanupamfootwear
 
John is suffering from fifth disease.It is caused by an airborne v.pdf
John is suffering from fifth disease.It is caused by an airborne v.pdfJohn is suffering from fifth disease.It is caused by an airborne v.pdf
John is suffering from fifth disease.It is caused by an airborne v.pdfanupamfootwear
 

More from anupamfootwear (20)

All of the aboveSolution All of the above.pdf
 All of the aboveSolution All of the above.pdf All of the aboveSolution All of the above.pdf
All of the aboveSolution All of the above.pdf
 
Yields a colorless solution and a white precipita.pdf
                     Yields a colorless solution and a white precipita.pdf                     Yields a colorless solution and a white precipita.pdf
Yields a colorless solution and a white precipita.pdf
 
ROund to one significant figures, THen, its 2..pdf
                     ROund to one significant figures,  THen, its 2..pdf                     ROund to one significant figures,  THen, its 2..pdf
ROund to one significant figures, THen, its 2..pdf
 
P=7.7(0.92)^t growth rate is dPdt differentiate .pdf
                     P=7.7(0.92)^t growth rate is dPdt differentiate .pdf                     P=7.7(0.92)^t growth rate is dPdt differentiate .pdf
P=7.7(0.92)^t growth rate is dPdt differentiate .pdf
 
option (D) ... reason posted in my previous answe.pdf
                     option (D) ... reason posted in my previous answe.pdf                     option (D) ... reason posted in my previous answe.pdf
option (D) ... reason posted in my previous answe.pdf
 
no.of moles of H2moles=28.82=14.4moles no.of mol.pdf
                     no.of moles of H2moles=28.82=14.4moles no.of mol.pdf                     no.of moles of H2moles=28.82=14.4moles no.of mol.pdf
no.of moles of H2moles=28.82=14.4moles no.of mol.pdf
 
Ionic Compounds Think of an ionic compound as a .pdf
                     Ionic Compounds Think of an ionic compound as a .pdf                     Ionic Compounds Think of an ionic compound as a .pdf
Ionic Compounds Think of an ionic compound as a .pdf
 
In the First molecule there will be Resonance whi.pdf
                     In the First molecule there will be Resonance whi.pdf                     In the First molecule there will be Resonance whi.pdf
In the First molecule there will be Resonance whi.pdf
 
He down the group, IE decreases. Solution.pdf
                     He   down the group, IE decreases.   Solution.pdf                     He   down the group, IE decreases.   Solution.pdf
He down the group, IE decreases. Solution.pdf
 
Uncouple agents will never disrupt the electron transport (they will.pdf
Uncouple agents will never disrupt the electron transport (they will.pdfUncouple agents will never disrupt the electron transport (they will.pdf
Uncouple agents will never disrupt the electron transport (they will.pdf
 
The N and O atoms are both sp2 hybridized.The sp2 hybrid orbitals .pdf
The N and O atoms are both sp2 hybridized.The sp2 hybrid orbitals .pdfThe N and O atoms are both sp2 hybridized.The sp2 hybrid orbitals .pdf
The N and O atoms are both sp2 hybridized.The sp2 hybrid orbitals .pdf
 
d.Addition of sulfuric acid to copper(II) oxide p.pdf
                     d.Addition of sulfuric acid to copper(II) oxide p.pdf                     d.Addition of sulfuric acid to copper(II) oxide p.pdf
d.Addition of sulfuric acid to copper(II) oxide p.pdf
 
The 2nd statement and 3rd statement follow the seed and soil theory .pdf
The 2nd statement and 3rd statement follow the seed and soil theory .pdfThe 2nd statement and 3rd statement follow the seed and soil theory .pdf
The 2nd statement and 3rd statement follow the seed and soil theory .pdf
 
S2F6SolutionS2F6.pdf
S2F6SolutionS2F6.pdfS2F6SolutionS2F6.pdf
S2F6SolutionS2F6.pdf
 
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdfQuicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
 
Pictures are not legible, could you plz post it again.Solution.pdf
Pictures are not legible, could you plz post it again.Solution.pdfPictures are not legible, could you plz post it again.Solution.pdf
Pictures are not legible, could you plz post it again.Solution.pdf
 
Carbonic acid leaves the soda solution as CO2 (ca.pdf
                     Carbonic acid leaves the soda solution as CO2 (ca.pdf                     Carbonic acid leaves the soda solution as CO2 (ca.pdf
Carbonic acid leaves the soda solution as CO2 (ca.pdf
 
C. III S.pdf
                     C. III                                      S.pdf                     C. III                                      S.pdf
C. III S.pdf
 
mass= density volume= 2.330.10.10.01 = 2.3310-4gmsatomic .pdf
mass= density volume= 2.330.10.10.01 = 2.3310-4gmsatomic .pdfmass= density volume= 2.330.10.10.01 = 2.3310-4gmsatomic .pdf
mass= density volume= 2.330.10.10.01 = 2.3310-4gmsatomic .pdf
 
John is suffering from fifth disease.It is caused by an airborne v.pdf
John is suffering from fifth disease.It is caused by an airborne v.pdfJohn is suffering from fifth disease.It is caused by an airborne v.pdf
John is suffering from fifth disease.It is caused by an airborne v.pdf
 

Recently uploaded

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
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
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Problem1 java codeimport java.util.Scanner; Java code to pr.pdf

  • 1. // Problem1 java code import java.util.Scanner; // Java code to print all possible strings of letter L and R class Problem1 { static void print(char set[], int length) { int setLength = set.length; printRecursion(set, "", setLength, length); } static void printRecursion(char set[], String prefixset, int setLength, int length) { // Base case: length is 0 if (length == 0) { System.out.println(prefixset); return; } for (int i = 0; i < setLength; ++i) { String newPrefixset = prefixset + set[i]; printRecursion(set, newPrefixset, setLength, length - 1); } } public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Enter length: "); int length = scan.nextInt(); char set[] = {'L', 'R'}; print(set, length); } } /* output: Enter length: 3
  • 2. LLL LLR LRL LRR RLL RLR RRL RRR */ // Problem2 java code import java.util.Scanner; // Java code to print all possible strings of letter L and R class Problem2 { static void print(char set[], int length) { int setLength = set.length; printRecursion(set, "", setLength, length); } static void printRecursion(char set[], String prefixset, int setLength, int length) { // Base case: length is 0 if (length == 0) { System.out.print(prefixset + " "); return; } for (int i = 0; i < setLength; ++i) { String newPrefixset = prefixset + set[i]; printRecursion(set, newPrefixset, setLength, length - 1); } } public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Enter length: "); int length = scan.nextInt(); char set[] = {'1', '3', '5', '7', '9'};
  • 3. print(set, length); System.out.println(); } } /* output: Enter length: 3 111 113 115 117 119 131 133 135 137 139 151 153 155 157 159 171 173 175 177 179 191 193 195 197 199 311 313 315 317 319 331 333 335 337 339 351 353 355 357 359 371 373 375 377 379 391 393 395 397 399 511 513 515 517 519 531 533 535 537 539 551 553 555 557 559 571 573 575 577 579 591 593 595 597 599 711 713 715 717 719 731 733 735 737 739 751 753 755 757 759 771 773 775 777 779 791 793 795 797 799 911 913 915 917 919 931 933 935 937 939 951 953 955 957 959 971 973 975 977 979 991 993 995 997 999 */ // Problem3 java code import java.util.Scanner; // Java code to multiply 2 numbers class Problem3 { public static int multiply(int a, int b) { int temp = b; for (int i = 1; i < a; i++ ) { b = b + temp; } return b; } public static void main(String[] args) { Scanner scan=new Scanner(System.in);
  • 4. System.out.println("Enter a: "); int a = scan.nextInt(); System.out.println("Enter b: "); int b = scan.nextInt(); System.out.println(a + "X" + b + " = " + multiply(a,b)); } } /* output: Enter a: 7 Enter b: 6 7X6 = 42 */ // Problem4 java code import java.util.Scanner; // Java code to find gcd 2 numbers class Problem4 { public static int gcd(int a, int b) { if (b!=0) return gcd(b, a%b); else return a; } public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Enter a: "); int a = scan.nextInt(); System.out.println("Enter b: "); int b = scan.nextInt(); System.out.println("gcd(" + a + "," + b + ") = " + gcd(a,b));
  • 5. } } /* output: Enter a: 10 Enter b: 12 gcd(10,12) = 2 */ Solution // Problem1 java code import java.util.Scanner; // Java code to print all possible strings of letter L and R class Problem1 { static void print(char set[], int length) { int setLength = set.length; printRecursion(set, "", setLength, length); } static void printRecursion(char set[], String prefixset, int setLength, int length) { // Base case: length is 0 if (length == 0) { System.out.println(prefixset); return; } for (int i = 0; i < setLength; ++i) { String newPrefixset = prefixset + set[i]; printRecursion(set, newPrefixset, setLength, length - 1); } } public static void main(String[] args) {
  • 6. Scanner scan=new Scanner(System.in); System.out.println("Enter length: "); int length = scan.nextInt(); char set[] = {'L', 'R'}; print(set, length); } } /* output: Enter length: 3 LLL LLR LRL LRR RLL RLR RRL RRR */ // Problem2 java code import java.util.Scanner; // Java code to print all possible strings of letter L and R class Problem2 { static void print(char set[], int length) { int setLength = set.length; printRecursion(set, "", setLength, length); } static void printRecursion(char set[], String prefixset, int setLength, int length) { // Base case: length is 0 if (length == 0) { System.out.print(prefixset + " "); return;
  • 7. } for (int i = 0; i < setLength; ++i) { String newPrefixset = prefixset + set[i]; printRecursion(set, newPrefixset, setLength, length - 1); } } public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Enter length: "); int length = scan.nextInt(); char set[] = {'1', '3', '5', '7', '9'}; print(set, length); System.out.println(); } } /* output: Enter length: 3 111 113 115 117 119 131 133 135 137 139 151 153 155 157 159 171 173 175 177 179 191 193 195 197 199 311 313 315 317 319 331 333 335 337 339 351 353 355 357 359 371 373 375 377 379 391 393 395 397 399 511 513 515 517 519 531 533 535 537 539 551 553 555 557 559 571 573 575 577 579 591 593 595 597 599 711 713 715 717 719 731 733 735 737 739 751 753 755 757 759 771 773 775 777 779 791 793 795 797 799 911 913 915 917 919 931 933 935 937 939 951 953 955 957 959 971 973 975 977 979 991 993 995 997 999 */ // Problem3 java code import java.util.Scanner;
  • 8. // Java code to multiply 2 numbers class Problem3 { public static int multiply(int a, int b) { int temp = b; for (int i = 1; i < a; i++ ) { b = b + temp; } return b; } public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Enter a: "); int a = scan.nextInt(); System.out.println("Enter b: "); int b = scan.nextInt(); System.out.println(a + "X" + b + " = " + multiply(a,b)); } } /* output: Enter a: 7 Enter b: 6 7X6 = 42 */ // Problem4 java code import java.util.Scanner; // Java code to find gcd 2 numbers class Problem4 { public static int gcd(int a, int b) {
  • 9. if (b!=0) return gcd(b, a%b); else return a; } public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Enter a: "); int a = scan.nextInt(); System.out.println("Enter b: "); int b = scan.nextInt(); System.out.println("gcd(" + a + "," + b + ") = " + gcd(a,b)); } } /* output: Enter a: 10 Enter b: 12 gcd(10,12) = 2 */