Java – Fibonacci Sequence in Array

email me

Compiled and tested here: http://www.browxy.com/

With Initialized Array

import java.util.Scanner;

public class FibSeries {

public static void main (String [] args){

// fib sequence
int [] x = {0,1,1,2,3,5,6,13,21,34,55};

int i;

for (i=0; i<x.length; i++){

// output
System.out.print(x[i] + " ");

}
}
}

// screen output
// 0 1 1 2 3 5 8 13 21 34 55

With For Loop

import java.util.Scanner;

public class FibSeries {

public static int fibonacci(int n) {
int x = 0;
int y = 1;

// compute fib sequence
for (int i = 0; i < n; i++) {
int z = x;
x = y;
y = z + y;
}
return x;
}

public static void main(String[] args) {

for (int i = 0; i < 11; i++) {
// output
System.out.print(fibonacci(i) + " ");
}
}
}

// screen output
// 0 1 1 2 3 5 8 13 21 34 55

Windows – Add Runonce Key

email me

Manually in HKEY_CURRENT_USER

REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v RunScript /t REG_SZ /d “C:\setup\script.cmd” /f

 

Manually in HKEY_USERS

REG ADD HKU\S-1-5-21-3492930481-2827506072-2794401122-1001\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v RunScript /t REG_SZ /d “C:\setup\script.cmd” /f

 

HKEY_CURRENT_USER via Script (or…SCCM)

REG LOAD HKU\TEMP “C:\Users\Default\ntuser.dat”
REG ADD HKU\TEMP\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v RunScript /t REG_SZ /d “C:\setup\script.cmd” /f
REG UNLOAD HKU\TEMP

 

All Profiles via Load and Unload via Script

FOR /D %%D IN (“C:\Users\*”) DO IF EXIST “%%D\NTUSER.DAT” REG LOAD HKU\TEMP “%%D\NTUSER.DAT” && (REG ADD HKU\TEMP\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v Reg_Value /t REG_SZ /d Reg_Data /f & REG UNLOAD HKU\TEMP)

 

Using PowerShell

$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
$regKey = "RunScript"
$regValue = "c:\setup\script.cmd"

IF(!(Test-Path $regPath))

{

New-Item -Path $regPath -Force | Out-Null

New-ItemProperty -Path $regPath -Name $regKey -Value $regValue -PropertyType STRING -Force | Out-Null}

ELSE {

New-ItemProperty -Path $regPath -Name $regKey -Value $regValue -PropertyType STRING -Force | Out-Null}

 

Using PowerShell App Deployment Toolkit

[scriptblock]$HKCURegistrySettings = {
Set-RegistryKey -Key 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce' -Name 'RunScript' -Value '"c:\setup\script.cmd"'-Type String -ContinueOnError:$True
}
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings

 

Using C# in Visual Studio


using Microsoft.Win32; //used by Registry

namespace PlayingAround
{
class WriteReg
{
public static void Main(string[] args)
{
// define variables
const string userRoot = "HKEY_CURRENT_USER";
const string subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
const string keyName = userRoot + "\\" + subkey;

// set registry key
Registry.SetValue(keyName, "RunScript", "C:\\setup\\script.cmd", RegistryValueKind.String);

}
}
}

 

Using AutoIt in SciTE-Lite

WriteReg()

Func WriteReg()
  ; Write key
  RegWrite("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", "RunScript", "REG_SZ", "C:\setup\script.cmd")
EndFunc ;==>WriteReg