Least Significant Bit / Char Array
Oct 29, 2014
So I am working on a project for my Java course and for whatever reason, I am absolutely struggling with this assignment. I've made some progress but I can't seem to completely wrap my head around the algorithm I'm being told to use. I feel that everything is correct up to a particular point.I believe I am having issues moving a char array into a char matrix.
package edu.cofc.csci221.ui;
import java.lang.*;
public class Decoder
{
private int[][] M;
[code]...
Would I just need to loop through lsb one at a time and assign them to sequential spots within D? Basically call my get binary value and such in the outer loop and then use the inner to loop through both arrays and reassign values?
View Replies
ADVERTISEMENT
Feb 13, 2014
i am working on the same project and i got the code to make them print going down but not sideways.
public class ArrayofHope
{
public static void main(String args[])
{
System.out.println("Decimal Character
");
for(int j = 65; j <= 90; j++)
{
System.out.print(j);
System.out.println(" " + (char)j); //Character
}
}
}
View Replies
View Related
Apr 12, 2015
I have an array of Strings, one on each line and I need to convert them into an array of char's.
For Example:
This
is
an
Example
of
what
my
input
is.
In order to accomplish that I did the following-
String[] lotsOfText = a.gettingAnArrayAsAReturn();
char [][] myCharArray = new char [lotsOfText.length] [lotsOfText.length];
for(int i=0; i<lotsOfText.length; i++){
for(int j=0;j<lotsOfText[i].length();j++){
myCharArray[i][j] = lotsOfText[j].charAt(j); }}
But whenever I try this and then try to print the output :
for (int i = 0; i < lotsOfText.length; i++) {
for (int j = 0; j < lotsOfText[i].length(); j++) {
System.out.print(myCharArray[i][j]);
}
}
I get nothing. I'm not sure what's the flaw in my logic, is it the char array initialization that's wrong or is it something else ?
View Replies
View Related
Jan 16, 2014
Goal this time is to take a charArray, copy it into another charArray while reversing the things in it.
E.g. charArray["!ollaH"] into charArrayNew["Hallo!"]
My first idea was to revert the stuff in the Array with a ! cause i saw earlier that u can work with that too revert booleans. Sadly i didnt happen to make it work.
Next thing i thought of was a for loop to go trough the charArray and copy every section into charArrayNew just at the opposite end.
Java Code:
import java.util.Arrays;
public class aufgabe43 {
public static void main(String[] asgr){
char[] charArray
[Code] .....
Eclipse doesn't show any errors, and as u told me last time i did include import java.util.Arrays; to output the array in the end.
When i try to compile the code eclipse returns with an error
Java Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 68
at aufgabe43.main(aufgabe43.java:8) mh_sh_highlight_all('java');
Which I frankly don't understand since the array . Length is exactly the same.
View Replies
View Related
Apr 10, 2014
I'm trying to take the information from one 2d char array and put it into another char array but instead of traversing the array left to right I want the new array to be top to bottom.
Example fg would be fh
hi gi
I'm having trouble getting the information from one to the other.
[code]public static char[][] translateIt(char[][] english){
int rows = english.length;
int columns = english[0].length;
char[][] chinese = new char[columns][rows];
for(int j=0; j < columns; j++){
for (int i = 0; i < rows; i++){
//chinese[i][j] = english; this is commented out because it didn't work.
}//Ending bracket of columns for loop
}//Ending bracket of rows for loop
return chinese;
}//Ending bracket of translateIt[code]
View Replies
View Related
Apr 15, 2015
How can I display this result.aJohny
I have array contain numberi create new char array and i want to check if a number is >= 90 in array then input A at the same index in char arraythen second part i want to check if char array contain "A" then a = a + 1.
The result is like this:
A: 5
B: 29
C: 38
D: 24
E: 12
F: 17
public class Test {
public static char[] grades(int[] getMarks) {
char[] grade = new char[getMarks.length];
for (int i = 0; i < getMarks.length; i++) {
if (getMarks[i] >= 90) {
[Code] .....
View Replies
View Related
Nov 16, 2010
I have a string array but each cell in the 1d string array stores each character the text file is :
"START START START
The quick brown fox jumps over the lazy dog 1234567890-= !"$%^&*()_+ QWERTYUIOP{}ASDFGHJKL:@~|ZXCVBNM<><? /.,mnbvcxzasdfghjkkl;'#][poiuytrewq789654123.0
+-*/``""$% hello this is a test file using all the characters availible on the keyboard for input END END END END"
so in the string it is:[0] = S, [1]=A, [2]=R ...ect along the text basically i need to convert each character in each cell of the 1d string array to its hesidecimal value..i have created my own method which will take in a char and return a string containing the charcters hex value.
public static String toHex(char c) {
char char2ascii = c;
int i = 0;
int num = (int) char2ascii;
String hex ="";
[code]...
what i want to do is run each cell through the toHex method so i eventually have a string array containing the hex value of each character in my text.
example..i want:
String[] hexarray = S, T, A, R, T
a run it through my method to convert to hex then it will become
String[] hexarray = 53, 54, 41, 52, 54
Im not allowed to use inbuilt libarys and classes to do the hex conversion thats why i have my own method for it .
View Replies
View Related
May 17, 2014
I am relatively new to java, and i am trying to create a window inside of a 2d char array, and eventually i will have to draw other shapes in this window. so for example
* * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * *
The problem is my window is not drawing correctly too the border, but a couple extra chars on the x columns. Here is code. The dimensions of the window will eventually be passed through scanner in main, if i ever work out how to even draw it.Also, in class we never learnt to use the Graphics class, so im pretty sure we are not supposed to use it.
public class Window
{ //default values
private int xRow;
private int yCol;
private char ch;
public char[][] windowz = new char[30][20]; //30,20 (yx)flat values cuz doesnt work
[code]....
View Replies
View Related
Mar 30, 2014
Example code that works:
Java Code: List<String> list = Arrays.asList(strDays); mh_sh_highlight_all('java');
My code that doesn't work:
Java Code: List<char> list = Arrays.asList(userInputChars); mh_sh_highlight_all('java');
Error that I get:
Assignment6_2.java.java:45: error: unexpected type
List<char> list = Arrays.asList(userInputChars);
^
required: reference
found: char
1 error
The entire program (that works, except for the error above):
Java Code:
import java.util.Collections;
import java.util.List;
import java.util.Arrays;
import java.util.Scanner;
class Assignment6_2 {
public static void main(String[] args) {
[Code] .....
View Replies
View Related
Apr 14, 2014
If I type
long z = 0xDeadCafe;
System.out.print(z);
I get a negative number as a result.
But if I append an L to the hex number:
long z = 0xDeadCafeL;
the resulting number is a positive one.
What the difference is between those two lines:
long z = 0xDeadCafeL;
and
long z = 0xDeadCafe;
(same as above, but without the suffix L).
If I don't append the L, is the msb (most significant bit) somehow still carried over to the resulting long variable and in the latter case, where I append an L, it is not and instead the value is filled up with 32 leading zeros (4 Byte difference between int and long)?
View Replies
View Related
Feb 13, 2015
I'm trying to find a word in an array of char.....but I'm stuck. How to formulate the code to step through the array and pick out the word. This is what I have so far...
public static void searchAcross(String string, char[][] puzzle) {
// Gets the number of rows in the matrix
int rowLength = puzzle.length;
//Gets the number of columns in the matrix.
int colLength = puzzle[0].length;
[Code] ....
View Replies
View Related
Mar 29, 2014
I'm trying to convert all letters in a 2D char array into number. As results, I want a = 0, b=1, c=2, ... z=25.
Then, I tried this as part of my code:
char [][] letters = {{'i', 'u'}, {'a', 'g'}, {'e', 'k'}};
for (int i = 0; i < letters.length; i++) {
for (int j = 0; j < letters[i].length; j++) {
if (letters[i][j] >= 'a' && letters[i][j] <= 'z') {
letters[i][j] = (char) ((letters[i][j] - 'a') + '0');
}
}
}
The result of my code is not what I expected before.
From 'a' to 'j', it worked well. But, from 'k' until 'z' it didn't print expected number.
What's wrong with my code and what is the correct way to fix it?
View Replies
View Related
Feb 8, 2014
What I'm trying to do is compare String input to a char array. Let me make it a little more plain, I'm working on a cipher assignment, and my line of thought is this: I will get String input from the user, COMPARE the characters in the string input to an alphabet array, which will then be compared to the cipher array so that the cipher's counterpart can be chosen over the alphabet's. Any way that I might compare the random input keyed in by the user to that alphabet array?
View Replies
View Related
Sep 29, 2014
Below mentioned classes, create object system accept in both way so what is it significant.
============
ABC obj = new Test();
Test obj = new Test();
==================
--file ABC class
class ABC{ public void disp() { System.out.println("disp() method of parent class"); }
public void abc() { System.out.println("abc() method of parent class"); } }
--file Test class
class Test extends ABC{ public void disp(){ System.out.println("disp() method of Child class"); }
public void xyz(){ System.out.println("xyz() method of Child class"); }
public static void main( String args[]) { //Parent class reference to child class object
ABC obj = new Test(); obj.disp(); obj.abc(); }}
View Replies
View Related
Feb 10, 2015
I have written an algorithm that compares the chars and returns all the found words in a 20x10 puzzle, but not for a 100x50 puzzle.
The puzzles are loaded in via text file and I have confirmed they're loading correctly.
guesses = String[] of search words
puzzle = char[][] of letters
Why it doesn't work on the large array?
Expected output:
word1, word2, word3
Actual output:
[blank line]
Here's the horizontal algorithm (row by row search)
//temp variable
ArrayList<String> temp = new ArrayList<String>();
try {
//for each guess word
for(String word : guesses) {
int count = 0;
[Code] .....
View Replies
View Related
Jun 27, 2014
I had a Rest web service call and get InputStream.Now i want to Write Input Stream to PrintWriter of servlet.So that it can be downloaded.I am able to write String and file can be downloaded using following code, i want it to work for Input streamFollowing is code:
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename="" + name + ".pdf"");
response.getWriter().write(is);
Write can take following:
write(String)
write(char[])
write(int)
write(String, int len, int off)
write(char[], int len, int off)
I think char[] will not harm PDF file which is going to download in it
View Replies
View Related
Jan 24, 2014
I wrote a little piece of code like so:
public class Oott
{
public static void main ( String[] arguments)
{
System.out.println( 1.0 / 13.0);
}
}
When I run this it prints out "0.07692307692307693". Is that an error? Rounded correctly it should be "0.07692307692307692", shouldn't it? The repeating series is "076923". Do the Java specs allow a value returned that's off in the least significant digit?
View Replies
View Related
Dec 7, 2014
I have an array that I filled with 30 random characters, but now I am trying to sort them in ascending order and the descending order using lambda expressions.
public class RandomCharacters {
public static void main(String args[]){
Random r =new Random();
char myarray[] = new char [30];
for (int i = 0 ; i < 30; i++)
[Code] ......
View Replies
View Related
Apr 5, 2014
When casting a char which is read from a file to an int, can i assume that the mapping used will be ASCII? I've learned that unicode uses ASCII mappings for the characters that overlap.
Are there any other possibilities for int values of one character? I still have trouble understanding character encodings.
View Replies
View Related
Oct 20, 2014
I was asigned to make a code that would limit the input to 1 character when asked for the initial of your middle name. So far I have the code ask for your first name then your last name and out put "Hello" firstname+last name. Im trying to add an 1 character middle itnitial in there.
View Replies
View Related
Mar 3, 2015
I was reading about the char data type in Java. I know that an unsigned 16 bit integer is used to represent a char. So we can write the assignments below:
char a = 65; // a will get the value 'A'
But the limit of the char value is 65535.
So I've tried out a few things with char and trying to understand them but I'm not sure how they work.
char a =(char) 70000;
char b = (char) -1;
In the first case I thought that 70000 % 65535 would happen internally and the unicode character present at that location would get stored in 'a' but if I do that I get the answer of 70000 % 65535 as 4465. But when I display 'a' it shows me the output as '?'. Clearly '?' isn't at 4465.
In the second case I have no clue what's happening but somehow when I display 'b' it shows me '?' again.
View Replies
View Related
Oct 14, 2014
I need making char[] to a string im not entirely sure what to change i'm just suppose to use a string value but the upperclassmen used char:
char[] number = clear.toLowerCase().toCharArray();
for(int c = 0; c < number.length; c++) {
if(digit[c] < 'a' || digit[c] > 'z')
continue;
[code]...
View Replies
View Related
Mar 16, 2014
I can't figure out how to have all of the random characters generated to go into the String. Below I can only get the last character to covert over to a String.
System.out.println("Original random character string:");
String printingString = "a";
for (int i = 0; i < 50; i++)//loop to obtain 50 random characters
{
char randomChar = (char) ((Math.random() * 255) +32);
System.out.print(randomChar);
printingString = Character.toString(randomChar); }
return printingString; }
View Replies
View Related
Jan 21, 2015
I'm trying to write something to will convert my Scanner input which will be either a string or a char toUpperCase but it is not working.
import java.io.File;
import java.util.Scanner;
public class UpperCase {
public static void main(String [] args) {
Scanner kb = new Scanner(System.in);
char reply;
[code]....
View Replies
View Related
Jan 9, 2015
I am trying to get user input for a char value and am having some difficulty getting input for a char value.
Java Code:
//imports packages
import java.io.*;
import java.text.DecimalFormat;
class ModuleCulminatingTask {
public static void main (String args []) {
//declares variables
float var3, var4;
long var5 = (int)(Math.random()*10);
[code]....
View Replies
View Related
Oct 14, 2014
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int hours = getHours(kb);
char major = getMajor(kb);
[code]....
I'm trying to return a char c,o, or x if that is their "major code" that the scanner grabbed.
View Replies
View Related