Как оно называется ? Я видел несколько по core java - мне не понравилось.You must be registered for see links
Обучающее видео по java для начинающих.
import java.util.Scanner;
import java.io.File;
import java.io.*;
import java.util.*;
import java.math.*;
class bintodec{
public static void main(String[] args) throws Exception{
int b,i,j, Step;
ArrayList myArray = new ArrayList();
Scanner sc = new Scanner(new File("in.txt"));
while (sc.hasNextInt()) {
b = sc.nextInt();
myArray.add(b);
}
int COUNT = 4;
int a = COUNT-1;
int Result = 0;
Object Mass[] = myArray.toArray();
/* for (j=0; j<4;j++){
System.out.println(Mass[j] + "\n");
}*/
for (i=0; i<COUNT; i++){
Result += Mass[i] * (int)Math.pow(2, a);
a--;
}
System.out.println(Result);
}
}
akel@akel-desktop:~/java/teach$ javac bintodec.java
bintodec.java:29: operator * cannot be applied to java.lang.Object,int
Result += Mass * (int)Math.pow(2, a);
^
Note: bintodec.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
import java.util.Scanner;
import java.io.File;
import java.util.Vector;
class BinToDec {
public static void main(String[] args) throws Exception {
int b, i, Step;
Vector<Integer> readedFromFile = new Vector<Integer>();
Scanner sc = new Scanner(new File("in.txt"));
while (sc.hasNextInt()) {
b = sc.nextInt();
readedFromFile.add(b);
}
int COUNT = 4;
b = COUNT-1;
int Result = 0;
for (i = 0; i < COUNT; i++) {
Result += (int)readedFromFile.get(i) * (int)Math.pow(2, b);
b--;
}
System.out.println(Result);
}
}
Почему не выходит?а как сконвертировать вектор в массив ?
с toArray() не выходит разобраться
ArrayList name = new ArrayList();
Object massivename[] = name.toArray();
А зачем конвертировать вектор в массив? Есть объективная причина?а как сконвертировать вектор в массив ?
с toArray() не выходит разобраться
public <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array. If the Vector fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this Vector.
If the Vector fits in the specified array with room to spare (i.e., the array has more elements than the Vector), the element in the array immediately following the end of the Vector is set to null. (This is useful in determining the length of the Vector only if the caller knows that the Vector does not contain any null elements.)
Integer [] arr = new Integer[readedFromFile.size()];
readedFromFile.toArray(arr);