Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Count and Say
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
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static String countAndSay(int n){ if(n == 1){ return "1"; } String s = countAndSay(n-1); StringBuilder sb = new StringBuilder(); char say = s.charAt(0); int count = 1; for(int i = 1;i<s.length();i++){ char c = s.charAt(i); if(c==say){ count++; } else{ sb.append(count).append(say); say = c; count = 1; } } sb.append(count).append(say); return sb.toString(); } public static void main(String args[]) { System.out.println("Hello, World!"); System.out.println(countAndSay(5)); } }
[
+
]
Show input
Compilation time: 0.82 sec, absolute running time: 0.16 sec, cpu time: 0.14 sec, memory peak: 18 Mb, absolute service time: 1 sec
edit mode
|
history
|
discussion
Hello, World! 111221
stackse - search stackoverflow differently