Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Maths1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
samuel.boulton
Maths1
Commits
c4fffa49
Commit
c4fffa49
authored
Dec 11, 2018
by
samuelboulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments
parent
9a8a7f15
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
26 deletions
+16
-26
Program.java
src/Program.java
+16
-26
No files found.
src/Program.java
View file @
c4fffa49
...
...
@@ -64,28 +64,6 @@ public class Program {
public
static
void
main
(
String
[]
args
)
{
int
[]
input
=
{
3
,
6
,
77
};
double
output
=
0.0
;
double
bracketsResult
=
0.0
;
double
powerResult
=
0.0
;
double
total
=
0.0
;
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
bracketsResult
=
(
double
)
input
[
i
]
/
2.0
;
System
.
out
.
println
(
bracketsResult
+
" bracket result"
);
powerResult
=
Math
.
pow
(
bracketsResult
,
i
/
2.0
);
System
.
out
.
println
(
i
+
" this is i"
);
System
.
out
.
println
(
powerResult
+
" this is powerResult"
);
total
=
total
+
powerResult
;
System
.
out
.
println
(
total
+
" this is total"
);
}
output
=
total
/
(
double
)(
input
.
length
+
3.0
);
System
.
out
.
println
(
output
+
" output"
);
// TODO Auto-generated method stub
}
...
...
@@ -94,11 +72,13 @@ public class Program {
public
static
int
[]
ConvertBinaryToInt
(
String
[]
binaryArray
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
binaryArray
.
length
];
int
[]
resultsArray
=
new
int
[
binaryArray
.
length
];
// for loop to go around the binary array
for
(
int
i
=
0
;
i
<
binaryArray
.
length
;
i
++)
{
// use the 'ConvertASingleWordToInt' method to work out each character
// then add each character to the resultsArray
resultsArray
[
i
]
=
ConvertASingleWordToInt
(
binaryArray
[
i
]);
}
...
...
@@ -108,17 +88,22 @@ public class Program {
public
static
int
ConvertASingleWordToInt
(
String
someWord
)
{
int
result
=
0
;
int
binCM
=
1
;
// making the characters from said 'someWord'
char
[]
binChar
=
someWord
.
toCharArray
();
// looping through the characters
for
(
int
i
=
0
;
i
<
binChar
.
length
;
i
++)
{
// making the program go through the characters backwards to get the correct result
int
binIndex
=
binChar
.
length
-
i
-
1
;
// if statement seeing if the character is a 1
if
(
binChar
[
binIndex
]
==
'1'
)
{
// if it is a 1 then do this calcualtion
result
=
result
+
binCM
;
}
// each time the loop goes round binCM doubles
binCM
=
binCM
*
2
;
}
...
...
@@ -130,9 +115,11 @@ public class Program {
public
static
int
[]
ConvertHexToInt
(
String
[]
hexArray
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
hexArray
.
length
];
// for loop to go around the hex array
for
(
int
i
=
0
;
i
<
hexArray
.
length
;
i
++)
{
// use the 'ConvertHexToInt' method to work out each character
// then add each character to the resultsArray
resultsArray
[
i
]
=
ConvertHexToInt
(
hexArray
[
i
]);
}
...
...
@@ -146,9 +133,12 @@ public class Program {
{
int
result
=
0
;
int
hexCM
=
1
;
// making the characters from said 'hexWord'
char
[]
hexChar
=
hexWord
.
toCharArray
();
// looping through the characters
for
(
int
i
=
0
;
i
<
hexChar
.
length
;
i
++)
{
// if the character is a certain character then do this calculation
int
hexIndex
=
hexChar
.
length
-
i
-
1
;
if
(
hexChar
[
hexIndex
]
==
'1'
)
{
result
=
result
+
(
hexCM
*
1
);}
if
(
hexChar
[
hexIndex
]
==
'2'
)
{
result
=
result
+
(
hexCM
*
2
);}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment