Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Concatenation example #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Bits/bits.shadow
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import shadow:io@Console;

class bits
{
public main( String[] args ) => ()
{
String temp;
Console con;

con.print("\nEnter an Integer: ");
(temp, ) = con.readLine();
con.printLine();
int num = temp.toInt();

con.print("Do you want to set, unset, or flip a bit? (s, u, f): ");
(temp, ) = con.readLine();
con.printLine();
code choice = temp->codes[0];

con.print("Which bit? (0-31): ");
(temp, ) = con.readLine();
con.printLine();
int bit = temp.toInt();

if(choice == 's')
bitset(num, bit);

else if(choice == 'u')
unset(num, bit);

else if(choice == 'f')
flip(num, bit);
}

public bitset(int num, int bit) => ()
{
Console con;

int temp = 1 << bit;
int new = temp | value;
con.printLine("The result of setting bit " # bit # " in " # num # " is " # new # ".\n");

}

public unset(int num, int bit) => ()
{
Console con;

int temp = 1 << bit;
temp = ~temp;
int new = temp & value;
con.printLine("The result of unsetting bit " # bit # " in " # num # " is " # new # ".\n");
}

public flip(int num, int bit) => ()
{
Console con;

int temp = 1 << bit;
int new = temp ^ value;
con.printLine("The result of unsetting bit " # bit # " in " # num # " is " # new # ".\n");
}
}
16 changes: 16 additions & 0 deletions Concatenation/Concatenation.shadow
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import shadow:io@Console;

class Concatenation
{
public main( String[] args ) => ()
{
Console con;

String count;

count = "One, " # 2 # ", Three, " # 2 + 2 # ", Five, " # 1 + 5 # ", Seven, " # 6 + 2 # ", Nine, " # 7 + 3;

con.printLine("\nLet's count from 1 to " # 4 + 6 # "!\n");
con.printLine(count # "\n" );
}
}
4 changes: 3 additions & 1 deletion HelloWorld/HelloWorld.shadow
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class HelloWorld
{
public main( String[] args ) => ()
{
Console:instance.printLine("Hello, World!");
Console con;

con.printLine("Hello, World!");
}
}
2 changes: 1 addition & 1 deletion Input Output/InputOutput.shadow
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class InputOutput
{
public main( String[] args ) => ()
{
Console con = Console:instance;
Console con;

String name, school, home, temp;
int age;
Expand Down
2 changes: 1 addition & 1 deletion Multiple Return Values/MultipleReturns.shadow
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class MultipleReturns
{
public main( String[] args ) => ()
{
Console con = Console:instance;
Console con;

String temp, evenOdd;
int num, squared, half, doubled, factorial;
Expand Down
9 changes: 5 additions & 4 deletions loops/Loops1.shadow
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ class Loops1 {

public main( String[] args ) => ()
{
Console con;
// print out all the agruments passed to this program
foreach(var i in args) {
Console:instance.printLine("Here's the args: " # i);
con.printLine("Here's the args: " # i);
}

int[,] multi = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
foreach(int a in multi) {
Console:instance.printLine("Here's the numbers: " # i);
foreach(int i in multi) {
con.printLine("Here's the numbers: " # i);
}
}
}
}