JAVA期末大作业

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

JAVA期末大作业

1.圆柱体:

import java.util.*;

public class cylinder {

public static void main(String[] args) {

double radius,height;

final double PI=3.14;

double area,volume;

Scanner s=new Scanner(System.in);

radius=s.nextDouble();

height=s.nextDouble();

area=2*PI*radius*radius+2*PI*radius*height;

volume=PI*radius*radius*height;

System.out.println("area="+area);

System.out.println("volume="+volume);

}

}

结果:

2.heap:

import java.util.*;

public class heap {

public static boolean isYearHeap(int x){

if(x%4==0||x%400==0){

return true;

}else{

return false;

}

}

public static void main(String args[]){

int i;

Scanner s=new Scanner(System.in);

i=s.nextInt();

if(isYearHeap(i)){

System.out.println("Heap");

}else{

System.out.println("Not a heap year");

}

}

}

结果:

3.符号:

import java.util.*;

public class test {

public static void main(String[] args) {

int a=60;/*60=0011 1100*/

int b=13;/*13=0000 1101*/

int c=0;

c=a&b;/*12=0000 1100*/

System.out.println("a&b="+c);

c=a|b;

System.out.println("a|b="+c);

c=a^b;

System.out.println("a^b="+c);

c=~a;

System.out.println("~a="+c);

c=a<<2;

System.out.println("a<<2="+c);

c=a>>2;

System.out.println("a>>2="+c);

c=a>>>2;

System.out.println("a>>>2="+c);

}

}

结果:

4.if语句:

import java.util.*;

public class area {

public static void main(String[] args) { double x,y;

Scanner s=new Scanner(System.in);

x=s.nextDouble();

y=s.nextDouble();

if((x*y>1&&x*y<4)||(x*y<-1&&x*y>-4)){ System.out.println("inside");

}else{

System.out.println("outside");

}

}

}

结果:

5.grade:

import java.util.*;

import javax.swing.JOptionPane;

public class grade {

public static void main(String[] args) {

String h=JOptionPane.showInputDialog("Input a letter:");

char grade=h.charAt(0);

switch(grade){

case'a':System.out.println("85~100");break;

case'b':System.out.println("70~84");break;

case'c':System.out.println("60~69");break;

case'd':System.out.println("<60");break;

default:System.out.println("error");

}

}

}

结果:

6.package com.tutorialspoint;

import ng.*;

public class BooleanDemo {

public static void main(String[] args) {

// create a Boolean object b

Boolean b;

// assign value to b

b = new Boolean(true);

// create a boolean primitive type bool

boolean bool;

// assign primitive value of b to bool

bool = b.booleanValue();

String str = "Primitive value of Boolean object " + b + " is " + bool; // print bool value

System.out.println( str );

}

}

7.窗口:

import javax.swing.*;

public class first {

public static void main(String args[])

{

JFrame first=new JFrame();

first.setSize(300,400);

first.setTitle("我的窗口");

first.setVisible(true);

相关文档
最新文档