-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLookNSay.java
More file actions
50 lines (49 loc) · 1.2 KB
/
Copy pathLookNSay.java
File metadata and controls
50 lines (49 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*2 i/p..num
1 num- start of series
2 num-length of series
eg. 4 6
14
1114
3114
132114*/
package project1;
import java.util.*;
public class LookNSay {
public static void main(String[] args){
String input,output=" ";
int LengthOfSeries;
int i=0,j=0,z=1,length;
Scanner sc=new Scanner(System.in);
System.out.println("Enter your starting number: ");
input=sc.nextLine();
System.out.println("Enter the length of number: ");
LengthOfSeries=sc.nextInt();
length=input.length();
for(;length<=LengthOfSeries;){
char[] newinput=input.toCharArray();
length=input.length();
if(length==1){
output="1"+newinput[0];
System.out.println(output);
}
for(i=0;i<length-1;i++){
if(newinput[j]==newinput[j+1]){
z++;
}
else{
output=""+z+""+newinput[j];
z=1;
}
j++;
if(j==(length-1)){
output=output+""+z+""+newinput[j];
System.out.print(output);
}
}
input=output;
length=input.length();
j=0;
z=1;
}
}
}