请问老师,做个项目的时候,是不是对着敲就好了
start方法下已经创建了一个Menu对象了,那我在二级子菜单下是不是可以直接调用这个Menu的addMenu不用重新创建Menu对象了啊
老师,这举例好像不是同一个Class吧
老师,这是我们的作业题,可以帮我解答一下吗
这是贪心算法的装箱问题,要求需要先降序排列,然后装箱使箱子数量最少,这个的运行结果不对,您可以帮孩子看看吗
#include<iostream>
using namespace std;
#define N 1000
int main(){
int n;
int v[N];//箱子的容量
int a[N];//物品的容量
int count=0;
int k[N];//装箱下标
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];//每个物品的容量
v[i]=100;//每个箱子容量
}
//int tep;
// n = sizeof(a) / sizeof(a[0]);
for ( i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
if (a[j] < a[j + 1])
int tep = a[j + 1];
a[j + 1] = a[j];
a[j] = tep;
int j = 0;
cout << "冒泡排序输出结果:(降序)" << endl;
while (j < n)
cout << a[j] << " ";
j++;
system("pause");
return 0;
for( i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i]<=v[j]){//如果物品容量小于箱子容量,则装箱
v[j]=v[j]-a[i];
k[i]=j;//记录装箱的箱子号
if(count<j)
count=j;//记录箱子个数
break;
for(i=1;i<=n;i++)
cout<<a[i]<<" "<<k[i]<<endl;
cout<<count<<endl;
老师好,请问获取一个类的class是不是类似于继承?
这一接视频里最后关闭的时候要有顺序的关闭吗?还是随便先关哪个?
请问老师,为什么说ArrayList 和LinkList 是物理结构呢,这两个集合是计算机存储器的存储形式吗
return 语句是不是代表整个程序结束了 跳出while死循环了啊
找到原因了……应该是t.start()~~~~~~~~~~
package com.bjsxt.homework.Thread; public class JoinThread { public static void main(String[] args) { System.out.println("main线程开始"); Thread t1 = new Thread(new A()); t1.start(); //new B().start(); for(int i =0;i<10;i++){ System.out.println(Thread.currentThread().getName()+"正在运行"+i); //i=3时,main被挂起,直到A执行完。 if (i == 3) { try { t1.join(); } catch (InterruptedException e) { e.printStackTrace(); } } } System.out.println("main线程结束"); } } class A implements Runnable{ Thread t = new B(); @Override public void run() { t.run(); for(int i =0;i<10;i++){ System.out.println(Thread.currentThread().getName()+"正在运行"+i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } //i=5时,A被挂起,直到B执行完。 if(i==5){ try { t.join(); } catch (InterruptedException e) { e.printStackTrace(); } } }} } class B extends Thread{ @Override public void run() { for(int i =0;i<10;i++){ System.out.println(Thread.currentThread().getName()+"正在运行!!!"+i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
com.bjsxt.homework.Thread; JoinThread { main(String[] args) { System..println(); Thread t1 = Thread(A()); t1.start(); (i =;i<;i++){ System..println(Thread.().getName()++i); (i == ) { { t1.join(); } (InterruptedException e) { e.printStackTrace(); } } } System..println(); } } A Runnable{ Thread = B(); run() { .run(); (i =;i<;i++){ System..println(Thread.().getName()++i); { Thread.(); } (InterruptedException e) { e.printStackTrace(); } (i==){ { .join(); } (InterruptedException e) { e.printStackTrace(); } } }} } B Thread{ run() { (i =;i<;i++){ System..println(Thread.().getName()++i); { Thread.(); } (InterruptedException e) { e.printStackTrace(); } } } }
代码:
运行结果:main线程开始main正在运行0main正在运行1main正在运行2main正在运行3Thread-1正在运行!!!0Thread-1正在运行!!!1Thread-1正在运行!!!2Thread-1正在运行!!!3Thread-1正在运行!!!4Thread-1正在运行!!!5Thread-1正在运行!!!6Thread-1正在运行!!!7Thread-1正在运行!!!8Thread-1正在运行!!!9Thread-1正在运行0Thread-1正在运行1Thread-1正在运行2Thread-1正在运行3Thread-1正在运行4Thread-1正在运行5Thread-1正在运行6Thread-1正在运行7Thread-1正在运行8Thread-1正在运行9main正在运行4main正在运行5main正在运行6main正在运行7main正在运行8main正在运行9main线程结束Process finished with exit code 0
请问为什么线程中不能创建线程呢???只有一个Thread1
/** * 定义馒头类 */ class mantou2{ private int id ; public int getId() { return id; } public void setId(int id) { this.id = id; } public mantou2(int id) { this.id = id; } } /** * 定义缓冲区 */ class buffer{ private mantou2[] mt = new mantou2[10]; private int index ; /** * 放馒头 */ public synchronized void push(mantou2 mantou2){ while (this.index == this.mt.length){ try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } notify(); this.mt[index] = mantou2 ; index++ ; } /** * 取馒头 */ public synchronized mantou2 pop(){ while (this.index == 0){ try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } notify(); this.index--; return this.mt[index] ; } } /** * 取馒头线程 */ class qumantou extends Thread{ buffer buffer = new buffer(); public qumantou(com.itbz.buffer buffer) { this.buffer = buffer; } @Override public void run() { for (int i = 0; i < 10;i++){ buffer.pop() ; System.out.println("取馒头" + i); } } } /** * 放馒头线程 */ class cunmantou extends Thread{ buffer buffer = new buffer(); public cunmantou(com.itbz.buffer buffer) { this.buffer = buffer; } @Override public void run() { for (int i = 0; i < 10;i++){ System.out.println("存馒头" + i); mantou2 mantou2 = new mantou2(i); buffer.push(mantou2); } } } public class ProductThread2 { public static void main(String[] args) { buffer buffer = new buffer(); cunmantou cunmantou = new cunmantou(buffer); qumantou qumantou = new qumantou(buffer); cunmantou.start(); qumantou.start(); } }
问题 在主方法中声明两个存取馒头的时候,要对存取馒头两个类进行增加有参构造方法而不能使用默认无参构造方法才能正常,如果使用无参构造方法时,程序会阻塞?为什么?这块不太理解
这里是什么问题我看了几遍没有发现问题,和老师写的应该一样的这个导入的包为什么会变成灰色
请问老师,key.hashCode()这里的意思就是取哈希值的低16位吗
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637