请用JAVA写一个程序:

用java编写一个程序~

public class Test {
public static void main(String[] args) {
while (true) {
System.out.print("请输入姓名:");
Scanner input = new Scanner(System.in);
String name = input.next();
System.out.println("请输入的姓名是:"+name);
}
}
}

public class Du1 {

public static void main(String[] args) {

int year = 2011;

if((year % 4 == 0 && year % 100 != 0) || (year % 4 == 0 && year % 100 == 0) ){
System.out.println("是闰年");
}else{
System.out.println("It is ");
}

}
}

public class PersonQueue {
Person head = new Person(0);
Person pointer;
Person last;
public static void main(String[] args) {
new PersonQueue().onStart(5);
}

public void onStart(int count){
if(count <= 0){
throw new IllegalArgumentException();
}
pointer = head;
for (int i = 1; i <= count; i++) {
Person p = new Person(i);
p.setPrevious(pointer);
pointer.setNext(p);
pointer = p;
}
last = pointer;

this.onRun();
}
private void onRun(){
while(head.next != null){
pointer = head.next;
int index = 1;
while(pointer.next != null){
if(index % 2 == 1){
Person p = pointer;
p.count(1);
System.out.println(" i was removed");
pointer = p.next;
p.previous.setNext(pointer);
pointer.setPrevious(p.previous);

}
else if(index % 2 == 0){
Person p = pointer;
p.count(2);
System.out.println(" i was offered the last");
pointer = p.next;
p.previous.setNext(pointer);
pointer.setPrevious(p.previous);
last.setNext(p);
last = p;
last.setNext(null);

}

index++;
}

if(index == 1){
pointer.count(1);
System.out.println(" i was removed");
break;
}

}

}

// ===========================================================
// Inner Class
// ===========================================================
class Person{
int pid = 0;
Person next = null;
Person previous = null;
public Person(int id){
this.pid = id;
}
public int getId(){
return pid;
}
public void count(int num){
System.out.print("my pid is:"+pid+" and i say:"+num +" so ");
}
public void setNext(Person p){
this.next = p;
}
public Person next(){
return next;
}
public Person previous() {
return previous;
}
public void setPrevious(Person previous) {
this.previous = previous;
}

}
}

=========================result==================

my pid is:1 and i say:1 so i was removed
my pid is:2 and i say:2 so i was offered the last
my pid is:3 and i say:1 so i was removed
my pid is:4 and i say:2 so i was offered the last
my pid is:5 and i say:1 so i was removed
my pid is:2 and i say:2 so i was offered the last
my pid is:4 and i say:1 so i was removed
my pid is:2 and i say:1 so i was removed

有空给你

编写一个JAVA程序读取0到50(包含两者)范围内的任意多个整数,并且计算每...
答:public class Test { public static void main(String[] args) { Map<Integer, Integer> map = new HashMap<>(); Scanner scanner = new Scanner(System.in); System.out.println("请输入0到50范围的数(输入-1结束)"); int num; // 输入 -1 则输入结束 while ((...

用java 编写一个程序,要求输入圆的半径,求圆的周长,面积.
答:实现思路:输入一个半径的值,之后即可求出周长和面积:代码举例:import javax.swing.JOptionPane;class account { public static void main(String[] args){ String radiusString = JOptionPane.showInputDialog(null ,"请输入半径 : " , "计算" , JOptionPane.QUESTION_MESSAGE);double radius = ...

用java写一个程序?
答:程序从2开始,一直到该数字的平方根之间的每个数字进行除法运算。如果该数字能被任何一个这些数字整除,那么它不是素数。请注意,在此程序中,我们使用了Java 7引入的"try-with-resources"语句来自动关闭文件输出流。这样可以确保即使在发生异常的情况下,文件输出流也会被正确关闭,以避免文件被损坏。

在java中编写程序,定义一个学生类
答:代码如下:package exam2;import java.util.ArrayList;import java.util.List;/ 编写一个Java应用程序,该程序包括3个类:定义一个学生类,Student有姓名,学号,选学的课程列表 定义一个课程类:课程名称,课程分数 (1)初始化一个学生,选择了三门课程,并添加到学生的属性中 (2)实现统计学生的总分...

使用JAVA编写一个程序
答:获取键盘输入Scanner scanner = new Scanner(System.in);// 用k来存储0~1000的随机数k = random.nextInt(1000);System.out.println("游戏开始,请输入一个在0~1000内的数");//用i来获取键盘输入i = scanner.nextInt();//当i不等于k时,进行循环while (i != k) {n++;if (i > k) {...

java编写一个程序,我连续输入 1 2 3 4 5 6 7 这7个数字,请编写一个程...
答:int num;//输入的数的个数 Scanner in = new Scanner(System.in);//用以接收用户输入 System.out.println("请输入待输入的数字个数");num = in.nextInt();//获取用户输入的数字个数 System.out.println("请输入"+num+"个数");for(int i=1;i<=num;i++){ data.add(in.nextInt())...

用java编写一个程序
答:代码如下:import java.util.Scanner;public class App {public static void main(String[] argv) {Scanner scanner = new Scanner(System.in);int num1 = scanner.nextInt();int num2 = scanner.nextInt();if (num1 > num2) {int temp = num1;num1 = num2;num2 = temp;}for (; ...

JAVA编写程序?
答:System.out.println("Hello world");} };} }class Inner { public static class InnerDemo { public static void main(String[] args) { Outer.method().show();} } } 这个程序中定义了一个接口 Inter 和一个外部类 Outer。Outer 类中有一个静态方法 method,该方法返回了一个实现了 ...

用java写一个程序
答:public static void main(final String[] args) { final Scanner scan = new Scanner(System.in);final int num =scan.nextInt();String str =String.valueOf(num);final String[] aa= str.split("");final int a1 = Integer.parseInt(aa[0]);final int a2 = Integer.parseInt(aa[1])...

用Java编写程序
答:s1=s1.delete(3,s1.length());//删除s1从第三个字符开始的所有字符。System.out.println(s1);StringBuffer s2=new StringBuffer(s.substring(7,10));//取s的一个子串s2(从第7个开始取出3个字符)。System.out.println(s2);s2.reverse();//将子串s2反转。System.out.println(s2);s1....

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网