java作业!!

	publicstaticvoidmain(String[]args){

容inta=10,num=100;
while(num<1000){
if(a*a==num){
System.out.println(a*a);
}
a++;
num=a*a;
}
}

㈡ JAVA用if条件结构做

这个应该满足你的要求。试试看吧。
是不是你们发的一个作业啊?
看到这个题三次了。好好理解理解吧。

import java.util.Scanner;

public class Test {

private final static char USER_NAME = '青';

private final static int PASSWORD = 123;

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
System.out.print("请输入用户名:");
String userName = input.next();
System.out.print("请输入密码:");
int passWord = input.nextInt();

if (userName.length() == 1 && userName.charAt(0) == USER_NAME && passWord == PASSWORD) {
System.out.println("欢迎你,青");
} else {
System.out.println("对不起,你不是青");
}
}
}

㈢ java作业!!!!

abstract class Check {

/**
* @param args
*/
public Check(){};
public void outHello(){
System.out.println("Hello");
}
public abstract void abstractM();//抽象方法

}

public class extendCheck extends Check{

public static void main(String[] args) {
//成功版 输出权father Hello Hello
Check check = new extendCheck();
check.abstractM();
check.outHello();

//
// 报错Check check2 = new Check();
}

@Override
public void abstractM() {
System.out.println("father Hello");
}

}

㈣ java 中if条件的用法请求详细解说

public class compare{ //定义类
static int a,b;
public static int function(int a,int b){

int c;
if(a>=b)

c=a;
this.a=b;
this.b=c;
}
public static void main(String[] args){
compare.function(x,y);
System.out.println("a:"+compare.a+"b:"+compare.b);
}

㈤ JAVA作业怎么做

importjava.util.Scanner;

publicclassGuessGame{

publicstaticvoidmain(String[]args){
startGuess();
}
publicstaticvoidstartGuess(){
Scannerin=newScanner(System.in);
intinput,random,fower=1,upper=13;
inti=1;
System.out.println("请开始输入想猜的正整数:");
while(true){
input=in.nextInt();
//生成fower到upperde随机数
random=(int)(Math.random()*(upper-fower+1)+fower);
if(input>random){
System.out.println("当前随机数"+random+"范围("+fower+","+upper+")");
System.out.println("大了");
upper=input-1;
fower=1;
}elseif(input<random){
System.out.println("当前随机数"+random+"范围("+fower+","+upper+")");
System.out.println("小了");
upper=13;
fower=input+1;
}elseif(i==1){
System.out.println("第一次输入就猜中,猜"+(int)(Math.random()*(upper-fower+1)+fower)+"的人将被惩罚!");
}else{
System.out.println("当前随机数"+random+"范围("+fower+","+upper+")");
System.out.println("猜中的人被惩罚");
System.out.println("GAMEOVER!");
break;
}
i++;
}

}

}

㈥ java-if嵌套结构的一个作业

publicclassUtil{
publicstaticvoidmain(String[]args){
.util.Scannersc=newjava.util.Scanner(System.in);
int[]arr=newint[3];
for(inti=0;i<arr.length;i++){
System.out.println("请输入第"+(i+1)+"个整数!");
try{
arr[i]=sc.nextInt();
}catch(Exceptione){
System.out.println("系统错误,您输入的不为整数!");
System.exit(0);
}
}
if(arr[0]==arr[1]&&arr[0]==arr[2]){
System.out.println("这三个数相等");
}elseif(arr[0]+arr[1]+arr[2]>1000){
System.out.println("这三个数之和大于1000");
}else{
System.out.println("这三个数之和不大于1000");
}
}
}

㈦ JAVA作业

classaccount{
//账户余额
intmoney;
//利率
doublerate;
//构造函数,money为账户初始存款,rate为初始利率
publicaccount(intmoney,doublerate){
this.money=money;
this.rate=rate;
}
//向账户里存x元
publicvoiddeposit(intx){
money+=x;
}
//从账户里取x元
publicvoidwithdrawal(intx){
//取款
money-=x;
//如果透支则收10元罚款
if(money<0)
money-=10;
}
//每个月调用以更新账户内容,newRate为下个月的利率
publicvoipdate(intnewRate){
money=money*(1+rate);
rate=newRate;
}
}

㈧ Java if嵌套作业

换成这个
if(A==B && A==C ){
System.out.println("三数相等回");
}
else if(A+B+C>1000){
System.out.println("大于答1000");
}
else{
System.out.println("小于1000");
}

㈨ JAVA编程作业

importjava.math.BigDecimal;
importjava.util.Random;

publicclassIncrease{

publicstaticbooleanisPrime(inta){

=true;

if(a<2){//素数不小于2
returnfalse;
}else{

for(inti=2;i<=Math.sqrt(a);i++){

if(a%i==0){//若能被整除,则说明不是素数,返回false

flag=false;
break;//跳出循环
}
}
}
returnflag;
}

publicstaticvoidtest1(){
inti,n,k=0;
System.out.println("1-1000内素数");
for(n=3;n<=1000;n++){//3~1000的所有数
i=2;
while(i<n){
if(n%i==0)break;//若能整除说明n不是素数,跳出当前循环
i++;
}


if(i==n){//如果i==n则说明n不能被2~n-1整除,是素数
k++;//统计输出数的个数
System.out.print(i+" ");
if(k%6==0)//每输出5个则换行
System.out.println();
}
}
}
publicstaticvoidtest2()
{
Randomr=newRandom();
System.out.println(r.nextInt(301)-100);
}
publicstaticinttest3(intm,intn){
//辗转相除法
intr;
do{
if(m<n)
{
r=m;
m=n;
n=r;
}
r=m%n;
m=n;
n=r;
}while(r!=0);
returnm;
}
publicstaticdoubletest4(intn){
doublee=1f;
doubletotal=1.0;
for(inti=0;i<n;i++)
{
total/=i+1;
e+=total;
}
BigDecimalb=newBigDecimal(e);
e=b.setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue();//表明四舍五入,保留四位小数
returne;
}
publicstaticvoidmain(String[]args){
//第一题测试
System.out.println(isPrime(131));
test1();
//第二题测试
test2();
//第三题测试
System.out.println("最大公约数为:"+test3(1302,19924));
//第四题测试
System.out.println("e="+test4(100));
}
}

运行结果:

true

1-1000内素数

3 5 7 11 13 17

19 23 29 31 37 41

43 47 53 59 61 67

71 73 79 83 89 97

101 103 107 109 113 127

131 137 139 149 151 157

163 167 173 179 181 191

193 197 199 211 223 227

229 233 239 241 251 257

263 269 271 277 281 283

293 307 311 313 317 331

337 347 349 353 359 367

373 379 383 389 397 401

409 419 421 431 433 439

443 449 457 461 463 467

479 487 491 499 503 509

521 523 541 547 557 563

569 571 577 587 593 599

601 607 613 617 619 631

641 643 647 653 659 661

673 677 683 691 701 709

719 727 733 739 743 751

757 761 769 773 787 797

809 811 821 823 827 829

839 853 857 859 863 877

881 883 887 907 911 919

929 937 941 947 953 967

971 977 983 991 997 106

最大公约数为:2

e=2.7183

㈩ java作业

下面一道一道的完成:
第一题:
1)快速排序
package src;

/*
* 有几个关键点
* 1 中间值到底取什么
* 2 i和j的比较什么时候需要是<=
* 3 递归调用的left和right值如何确定
*/

public class QuickSort { //快速排序

public static void main(String[] args) {

int[] a = {100,40, 60, 87, 34, 11, 56, 0};
int left = 0 ;
int right = a.length - 1;
quickSort(a , left , right);

//循环显示数组
for(int i = 0 ; i < a.length ; i++){
System.out.print(a[i] + " ");
}
}

public static void quickSort(int[] a , int left , int right ){
int middle , temp ;
int i = left ;
int j = right ;
middle = a[left];
while(i < j){
while((a[i] < middle) && (i < right)){
i++;
}
while((a[j] > middle) && (j > left)){
j--;
}
if(i <= j){
temp = a[i];
a[i] = a[j];
a[j] = temp;
i++;
j--;
}

}
if(left < j){
quickSort(a , left , j);
}
if(right > i){
quickSort(a , i , right);
}
}
}

2)冒泡排序

package src;

public class PopSort {
public static void main(String[] args) {

int[] a = {100,40, 60, 87, 34, 11, 56, 0};
for(int i = 0 ; i < a.length ; i++)
for(int j = 0 ; j < a.length - i -1 ; j++){
if(a[j] > a[j+1]){
int temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
for(int k = 0 ; k < a.length ; k++){
System.out.print(a[k] + " ");
}
}
}

第二题

package src;

public class BinarySearch {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {

int[] datas = { 1, 2, 3, 4, 5, 6 ,7, 8, 9, 10}; //二分法必须应用在有序数组
int key = 9;
System.out.println("the result is " + bSearch(datas , key));

}
public static int bSearch(int[] datas , int key){
int index = -1;
int low = 0;
int high = datas.length - 1;
while (low <= high) {
int middle = (low + high) >> 1;
if (key == datas[middle]) {
index = middle;
break;
} else if (key > datas[middle]) {
low = middle + 1;
} else if (key < datas[middle]) {
high = middle - 1;
}
}
return index;
}

}

第三题

package src;

public class CharCode {
public static void main(String[] args){
String str = "hello world";
char[] strToChar = str.toCharArray();
int charSum = 0;
for(int i = 0 ; i < strToChar.length ; i++){
charSum = charSum + strToChar[i];
}
System.out.print("the charArray's Sum is " + charSum);
}

}

第四题

package src;

public class NewArray {

/**
* @param args
*/
public static void main(String[] args) {
int a[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
int[] b = new int[a.length];
int j = 0;
for(int i = 0 ; i < a.length ; i++){
if(a[i] != 0){
b[j] = a[i];
j++;
}
}
for(int k = 0 ; k < j ; k++){
System.out.print(b[k] + " ");
}

}

}

第五题:

ArrayList实现

package src;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class StudentList {

/**
* @param args
*/
public String name;
public int age;
public String grade;
public String school;

public static List stuList = null;

public StudentList(String name, int age, String grade, String school) {
super();
this.name = name;
this.age = age;
this.grade = grade;
this.school = school;
}

public static void main(String[] args) {
stuList = new ArrayList();
stuList.add(new StudentList("aaa",13 , "6" ,"tianjin"));
stuList.add(new StudentList("kkk",13 , "6" ,"tianjin"));
stuList.add(new StudentList("ddd",13 , "6" ,"shenzhen"));
stuList.add(new StudentList("ccc",13 , "6" ,"beijing"));
stuList.add(new StudentList("eee",15 , "6" ,"tianjin"));
stuList.add(new StudentList("aaa",13 , "6" ,"tianjin"));
stuList.add(new StudentList("kkk",13 , "6" ,"tianjin"));
stuList.add(new StudentList("ddd",13 , "6" ,"shenzhen"));
stuList.add(new StudentList("ccc",13 , "6" ,"beijing"));
stuList.add(new StudentList("eee",15 , "6" ,"tianjin"));

for(Iterator it = stuList.listIterator() ; it.hasNext(); ){
StudentList stu = (StudentList)it.next();
System.out.println(stu.name + " ," +stu.age + " ," + stu.grade + " ," + stu.school );
}
}

}

数组实现:

package src;

public class StudentArray {

/**
* @param args
*/
public String name;
public int age;
public String grade;
public String school;

public StudentArray(String name, int age, String grade, String school) {
super();
this.name = name;
this.age = age;
this.grade = grade;
this.school = school;
}

public static void main(String[] args) {
StudentArray[] stua = {new StudentArray("aaa" ,13 ,"4" ,"beijing") , new StudentArray("bbb" ,14 ,"4" ,"dalian") ,new StudentArray("ddd" ,13 ,"4" ,"beijing") ,new StudentArray("ccc" ,13 ,"4" ,"tianjin") ,new StudentArray("eee" ,20 ,"8" ,"beijing") ,new StudentArray("fff" ,23 ,"10" ,"beijing") ,new StudentArray("aaa" ,13 ,"4" ,"beijing") ,new StudentArray("aaa" ,13 ,"4" ,"beijing") ,new StudentArray("kkk" ,13 ,"4" ,"beijing") ,new StudentArray("www" ,13 ,"4" ,"beijing") ,new StudentArray("aaa" ,13 ,"4" ,"beijing") };
for(int i = 0 ; i < stua.length ; i++){
System.out.println(stua[i].name + " , " + stua[i].age + " , " +stua[i].grade + " , " +stua[i].school);
}
}

}

第六题:

package job;

public abstract class Job { //这个是父类抽象类,表示职业类

public double baseWage; //基本工资

public Job(double baseWage) {
super();
this.baseWage = baseWage;
}

public double getBaseWage() {
return baseWage;
}

public void setBaseWage(double baseWage) {
this.baseWage = baseWage;
}

public double getYearWage(){ //一年的工资
return baseWage * 12 ;
}
}

package job;

public class Farmer extends Job {

public Farmer(double baseWage) {
super(baseWage);
// TODO 自动生成构造函数存根
}

public double getYearWage() {
// TODO 自动生成方法存根
return super.getYearWage();
}

}

package job;

public class Scientist extends Job {
public String yearendBonus; //年终奖
public Scientist(double baseWage) {
super(baseWage);
//
}

public String getYearendBonus() {
return yearendBonus;
}

public void setYearendBonus(String yearendBonus) {
this.yearendBonus = yearendBonus;
}

public double getYearWage() {
//
return super.getYearWage();
}

}

package job;

public class Teacher extends Job {
public double reward; //每天的课酬

public Teacher(double baseWage) {
super(baseWage);
// TODO 自动生成构造函数存根
}

public double getReward() {
return reward;
}

public void setReward(double reward) {
this.reward = reward;
}

public double getYearWage() {
// TODO 自动生成方法存根
return super.getYearWage();
}

}

package job;

public class Waiter extends Job {

public Waiter(double baseWage) {
super(baseWage);
// TODO 自动生成构造函数存根
}

public double getYearWage() {
// TODO 自动生成方法存根
return super.getYearWage();
}

}

package job;

public class Worker extends Job {

public Worker(double baseWage) {
super(baseWage);
// TODO 自动生成构造函数存根
}

public double getYearWage() {
// TODO 自动生成方法存根
return super.getYearWage();
}

}

package job;

public class Manager { //这是一个管理各种职业工资的类,这是一个含有具体业务的类

/**
* @param args
*/
public static void main(String[] args) {

Teacher tjob = new Teacher(5000); //教师的工资是5000美金一个月
printSalary(tjob);
Scientist sjob = new Scientist(8000);
printSalary(sjob);
Farmer fjob = new Farmer(4000);
printSalary(fjob);
Waiter wjob = new Waiter(3500);
printSalary(wjob);
Worker workjob = new Worker(4500);
printSalary(workjob);

}

public static void printSalary(Job job) {
System.out.println(job.getYearWage());
}

}

第七题:

package src;

public class Writer {

/**
* @param args
*/
public static void main(String[] args) {
int i = 911;
float j = 911.911f;
String str = "hello world";
write(i);
write(j);
write(str);
}

public static void write(int s) {
System.out.print("int: " + s + "\n");
}

public static void write(float s) {
System.out.print("float:" + s + "\n");
}

public static void write(String s) {
System.out.print("String:" + s + "\n");
}

}

好困啊,睡觉了