Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
LeftAndRightShiftStrings
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Text; namespace Rextester { public class Program { public static void Main(string[] args) { String str = "Hello world!"; leftshift(str,3); rightshift(str,3); } public static void leftshift(String str, int n) { StringBuilder sb = new StringBuilder(); String temp = reverse(str.Substring(0,n)); sb.Append(str.Substring(n-1,str.Length-n)+ temp.ToString()); Console.WriteLine("Left shifted " +sb.ToString()); } public static void rightshift(String str, int n) { StringBuilder sb = new StringBuilder(); String temp = reverse(str.Substring(str.Length-n,n)); sb.Append(temp.ToString() + str.Substring(0,str.Length-n)); Console.WriteLine("Right shifted " + sb.ToString()); } public static String reverse(String st) { StringBuilder sb = new StringBuilder(); int i=0; for(i= st.Length-1; i>=0; i--) { sb.Append(st[i]); } return sb.ToString(); } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,14 sec, absolute running time: 0,11 sec, cpu time: 0,09 sec, average memory usage: 12 Mb, average nr of threads: 2, absolute service time: 0,27 sec
edit mode
|
history
|
discussion
Left shifted llo worldleH Right shifted !dlHello wor