1,怎么用java写一个类class Bprivateint a;//声明变量 public B()//构造函数}public void setA(int a)//设置a的值this.a=a;}public int getA()//获取a的值return a;}public public static void main(String[] args)//必须要的主函数B b=new B();//建立一个B的对象bb.setA(3);//调用b对象里的方法setA();System.out.println(b.getA);//输出a}}【java单独编译一个类,怎么用java写一个类】
2,JAVA如何在运行时编译一个类使用jdk1.6提供的JavaCompiler类 。使用时一定要保证你的classpath的jre是jdk1.6,不能是纯jre,不然会出问题 。public class testString str = "public class test1String fileName ="d:/src/test1.java";//路径随便写File f = new File(fileName);FileWriter fw = new FileWriter(f);fw.write(src);fw.flush();fw.close();JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();StandardJavaFileManager fileMgr = compiler.getStandardFileManager(null, null, null);Iterable units = fileMgr.getJavaFileObjects(fileName);CompilationTask t = compiler.getTask(null, fileMgr, null, null, null, units);t.call();fileMgr.close();}基本上是classpath配置错了 。删掉这个环境变量,因为现在这个环境变量不是必需的了 。少了当前路径 .你的问题说得太不清楚了 。。是不是问把修改后的java类编译好后 , 再发布到服务器上?重新发布java类,服务器一般会自动重起,然后加载这个类 。
3,编写一个Java应用程序在其中编写一个类JAVA也应用程序 你进水了 JAVA写应用程序拉吉的一比 也web 还差不多 麻烦 还要设计界面 直接易语言 1分钟搞定 手机应用的话 除外import java.util.*;public class yugi public static void main(string[] args) scanner scan = new scanner(system.in); system.out.println("输入班级人数:"); int num = scan.nextint(); double sum = 0; double max = double.min_value; double min = double.max_value; for(int i = 0; i < num; i++) system.out.print("输入第" + (i + 1) + "个学生的成绩: "); double score = scan.nextdouble(); sum += score; max = score > max ? score : max; min = score < min ? score : min; } scan.close(); double avg = sum / num; system.out.printf("班级人数: %d,最高分: %.2f,最低分: %.2f,平均分: %.2f", num, max, min, avg); }}package practice1;public class Cprivate double a; private double b; private double c; private double[] d; public String[] i; public void setValue(double a, double b, double c)this.a = a;this.b = b;this.c = c;this.d = new double[2];this.i = new String[2]; } public boolean canGetValue()double temp;temp = b * b - 4 * a * c;if (temp < 0)this.i[0] = (-b) / (a * 2) + "+" + Math.sqrt(-temp) / (2 * a) + "i";this.i[1] = (-b) / (a * 2) + "-" + Math.sqrt(-temp) / (2 * a) + "i";return false;} elsethis.d[0] = (-b + Math.sqrt(temp)) / (2 * a);this.d[1] = (-b - Math.sqrt(temp)) / (2 * a);return true;} } /*** @param args*/ public double getA()return a; } public double getB()return b; } public double getC()return c; } public double getD(int i)return d[i]; } public static void main(String[] args)// TODO Auto-generated method stub C pratice1 = new C();pratice1.setValue(1, 3, 4);if (pratice1.canGetValue())System.out.println(pratice1.getA());System.out.println(pratice1.getB());System.out.println(pratice1.getC());System.out.println(pratice1.getD(0));System.out.println(pratice1.getD(1));} elseSystem.out.println(pratice1.i[0]);System.out.println(pratice1.i[1]);} }}
推荐阅读
- ipad怎么重新写码,iPad忘记ID账号密码怎么办 如何重新设置密码
- 176复古大极品无任务传奇手游,有没有好玩的176复古传奇游戏
- 北斗卫星导航系统要收费吗,北斗导航是不是要收费的
- 国外id账号和密码免费用,谁有苹果手机ID账号密码借用一下我要的是国外苹果ID账号密码的比如日
- 仙剑奇侠传苹果手机单机版下载,我比较怀旧突然想玩仙剑奇侠传doss版苹果手机怎么能下载求解
- 苹果有什么好玩的手机游戏推荐,iPhone上 好玩的游戏推荐几个我喜欢有很好的剧情的角色扮演
- 手机编写代码,手机如何编程
- 三轴加工中心编程自学教程,三菱加工中心的编程及指令 怎样学起快
- c语言程序中的文件包含命令是,c语言 文件包含命令