Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class s5535512037h1{
- public static void main(String args[]){
- int i, uInp = 0;
- if(args.length==1){
- try{
- uInp = Integer.parseInt(args[0]);
- }
- catch(NumberFormatException nfe){
- System.out.println(nfe.getMessage() + "\n The first argument must be an integer.");
- System.exit(1);
- }
- int[] sn = new int[uInp];
- for(i=0; i<uInp; i++)
- {
- if(i == 0 || i == 1)
- sn[i]=1;
- else if(i == 2)
- sn[i]=2;
- else if(i == 3)
- sn[i]=3;
- else if((i%3) == 0)
- sn[i]=sn[i-1];
- else
- sn[i]=(sn[i-2]*2)-1;
- System.out.print(sn[i] + " ");
- }
- }else{
- System.out.println("\n This program requires least one argument.");
- }
- }
- public static int findSn(int n, boolean dep){
- if(n<1) return 1;
- if(dep)System.out.print(findSn((n-1), true) + "\t");
- switch(n){
- case 0: case 1: return 1;
- case 2: return 2;
- case 3: return 3;
- default:
- if(n%3==0)
- return (findSn((n-1), false));
- else
- return (findSn((n-2), false)*2)-1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement