Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
584 views

Online Java Compiler - Online Java Editor - Java Code Online

This document contains Java code for generating all permutations of a string using recursion. It imports the Scanner class, defines a Permutations class with a permute method that takes a string, starting index, and ending index as parameters. The permute method recursively calls itself, swapping characters at different indices to generate all permutations and printing them out. It also defines a swap method to swap two characters in a string. The main method takes user input, calls the permute method, and executes the program.

Uploaded by

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

Online Java Compiler - Online Java Editor - Java Code Online

This document contains Java code for generating all permutations of a string using recursion. It imports the Scanner class, defines a Permutations class with a permute method that takes a string, starting index, and ending index as parameters. The permute method recursively calls itself, swapping characters at different indices to generate all permutations and printing them out. It also defines a swap method to swap two characters in a string. The main method takes user input, calls the permute method, and executes the program.

Uploaded by

Harsha Vardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5/13/2020 Online Java Compiler - Online Java Editor - Java Code Online

Sponsored: The Ruby Blend Podcast 🎧 Episode #11 "Open Source Funding" Listen

Online Java Compiler IDE


For Multiple Files, Custom Library and File Read/Write, use our new - Advanced Java IDE

Project Name: PER1


1 import java.util.*;
2 class permutations{
3
4 void permute(String str, int l, int r){
5 if (l==r){
6 System.out.println(str);
7 }
8 else{
9 for(int i=0;i<=r;i++){
10 str=swap(str,l,i);
11 permute(str,l+1,r);
12 str=swap(str,l,i);
13 }
14 }
15 }
16 String swap(String a, int m, int n){
17 char c[]=a.toCharArray();
18 char temp=c[n];
19 c[n]=c[m];
20 c[m]=temp;
21 return (String.valueOf(c));
22 }
23
24
25 }
26
27
28 public class MyClass {
29
30 public static void main(String args[]) {
31 Scanner sc=new Scanner(System.in);
32 String s=sc.nextLine();int l=s.length();
33 permutations p1=new permutations();
34 p1.permute(s,0,l-1);
35
36 }
37 }

   Execute Mode, Version, Inputs & Arguments

CommandLine Arguments

Stdin Inputs

Result

https://www.jdoodle.com/online-java-compiler/ 1/2
5/13/2020 Online Java Compiler - Online Java Editor - Java Code Online

Thanks for using our

Online Java Compiler IDE


to execute your program

Know Your JDoodle JDoodle For Your Organisation


JDoodle Supports 72 Languages and Do you have any specific compiler
2 DBs. Click here to see all. requirements?

Fullscreen - side-by-side code and Do you want to integrate compilers


output is available. click the " " icon near with your website, webapp, mobile app,
execute button to switch. courses?

Dark Theme available. Click on " " Do you need more than our Embed
icon near execute button and select dark and API features?
theme.
Looking for Multiple Files,
You can embed code from JDoodle Connecting to DB, Debugging, etc.?
directly into your website/blog. Click here
Are you building any innovative
to know more.
solution for your students or recruitment?
JDoodle offers an API service. You
Want to run JDoodle in-house?
can execute programs just by calling our
API. Click here to know more. Custom Domain, White labelled
pages for your institute?
If you like JDoodle, Please share us in
Social Media. Click here to share. Contact us - We are happy to help!

Check our Documentation Page for


more info.

JDoodle is serving the programming


community since 2013

https://www.jdoodle.com/online-java-compiler/ 2/2

You might also like