我尝试将类导入到此包但它不会编译 [英] L try to import class to this package but it wont compile
本文介绍了我尝试将类导入到此包但它不会编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试遵守代码,但是有一个错误,并且我使用blue j和net bean编译器作为bleo代码导入到类
import java.text.DecimalFormat;
import java.util.Random;
public class AverageSpeedOfStructures
{
public static void main( String args [])
{
// 创建一个ArrayClass对象
ArrayClass array = new ArrayClass( 1000000 );
// 创建SingleLinkedList类对象
SingleLinkedList< Integer> ; sll = new SingleLinkedList< Integer>();
// 创建一个随机对象
Random rand = < span class =code-keyword> new Random();
// 创建一个DecimalFormat对象
DecimalFormat form = < span class =code-keyword> new DecimalFormat( ##。####< /跨度>);
// 声明所需的变量来计算和存储
double totalofArray = 0 ;
double totalofSLL = 0 ;
long arrInsert,arrDelete,arrSearch;
long sllInsert,sllDelete,sllSearch;
long start,end;
// 查找插入方法所用时间的逻辑
start = System.nanoTime();
for ( int i = 0 ; i< 1000000 ; i ++)
{
array.insert(rand.nextInt( 1000 跨度>));
}
end = System.nanoTime();
arrInsert = Math.abs(start - end);
// 查找搜索方法所用时间的逻辑
start = System.nanoTime();
array.search( 300 );
end = System.nanoTime();
arrSearch = Math.abs(start - end);
// 查找删除方法所用时间的逻辑
start = System.nanoTime();
array.delete( 300 );
end = System.nanoTime();
arrDelete = Math.abs(开始 - 结束);
// ArrayClass使用数组所花费的平均时间
totalofArray =(arrInsert + arrDelete + arrSearch)/ 3 。 0 ;
// 单个链接列表速度
// 用于查找插入方法所用时间的逻辑
start = System.nanoTime();
for ( int i = 0 ; i< 1000000 ; i ++)
{
sll.listInsert(rand.nextInt( 1000 跨度>));
}
end = System.nanoTime();
sllInsert = Math.abs(start - end);
// 查找搜索方法所用时间的逻辑
start = System.nanoTime();
sll.listSearch( 300 );
end = System.nanoTime();
sllSearch = Math.abs(开始 - 结束);
// 查找删除方法所用时间的逻辑
start = System.nanoTime();
sll.listRemove( 300 );
end = System.nanoTime();
sllDelete = Math.abs(开始 - 结束);
// 单链表的平均时间
totalofSLL =(sllInsert + sllDelete + sllSearch)/ 3 。 0 ;
// 打印速度比率
System.out
.println( 未分类优化的平均速度比率
+ 数组结构\ n \\ n
+ 单链表结构为:\ n
+ form.format(totalofArray)
+ :
+ form.format(totalofSLL));
}
}
为什么会出错?
我尝试了什么:
l尝试从java导入这两个类但代码不会编译,错误在哪里?
解决方案
您还没有定义两个类ArrayClass
和SingleLinkedList< Integer>
l try to complies the code but there is an error and l did import to classes using both blue j and net bean compiler as bleo code
import java.text.DecimalFormat;
import java.util.Random;
public class AverageSpeedOfStructures
{
public static void main(String args[])
{
//create a ArrayClass object
ArrayClass array = new ArrayClass(1000000);
//create a SingleLinkedList class object
SingleLinkedList<Integer> sll = new SingleLinkedList<Integer>();
//create a Random object
Random rand = new Random();
//create a DecimalFormat object
DecimalFormat form = new DecimalFormat("##.####");
//declare the required variables to calculate and store
double totalofArray = 0;
double totalofSLL = 0;
long arrInsert, arrDelete, arrSearch;
long sllInsert, sllDelete, sllSearch;
long start, end;
//logic to find the time taken by insert method
start = System.nanoTime();
for (int i = 0; i < 1000000; i++)
{
array.insert(rand.nextInt(1000));
}
end = System.nanoTime();
arrInsert = Math.abs(start - end);
//logic to find the time taken by search method
start = System.nanoTime();
array.search(300);
end = System.nanoTime();
arrSearch = Math.abs(start - end);
//logic to find the time taken by delete method
start = System.nanoTime();
array.delete(300);
end = System.nanoTime();
arrDelete = Math.abs(start - end);
//average time taken by the ArrayClass using arrays
totalofArray = (arrInsert + arrDelete + arrSearch) / 3.0;
// Single LinkedList speeds
//logic to find the time taken by insert method
start = System.nanoTime();
for (int i = 0; i < 1000000; i++)
{
sll.listInsert(rand.nextInt(1000));
}
end = System.nanoTime();
sllInsert = Math.abs(start - end);
//logic to find the time taken by search method
start = System.nanoTime();
sll.listSearch(300);
end = System.nanoTime();
sllSearch = Math.abs(start - end);
//logic to find the time taken by delete method
start = System.nanoTime();
sll.listRemove(300);
end = System.nanoTime();
sllDelete = Math.abs(start - end);
//average time taken by the singly linked list
totalofSLL = (sllInsert + sllDelete + sllSearch) / 3.0;
//print the ratio of speeds
System.out
.println("The ratio of averge speed of an Unsorted-Optimized"
+ " array structure \nto the average speed of a"
+ " Singly Linked List structure is: \n"
+ form.format(totalofArray)
+ " : "
+ form.format(totalofSLL));
}
}
why there is an error?
What I have tried:
l did try to import both classes form java but the code wont compile and where is the error ??
解决方案
You have not defined the two classesArrayClass
andSingleLinkedList<Integer>
.
这篇关于我尝试将类导入到此包但它不会编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文