当前位置:编程学习 > JAVA >>

java小程序练习

/*
 * 1.byte byte_n1;
 *   short short_n1 = 10;
 *   short short_n2;
 *   int int_n1 = 3000000;
 *   int int_n2, int_n3;
 *   long long_n1 = 400;
 *   long long_n2, long_n3;
 *   byte_n1 = short_n1;
 *   byte_n1 = (byte) short_n1;
 *   short_n2 = (short) int_n1;
 *   int_n2 = int_n1 * short_n1;
 *   int_n3 = long_n1 * short_n1;
 *   long_n2 = int_n1 * 2000;
 *   long_n3 = int_n1 * 2000L;
 * 2.上机验证
 * public class Example {
 *   public static void main(String[] args) {
 *    int a = 20, b = 50, c = 100, d;
 *    a %= 9;
 *    b /= 7;
 *    c %= b;
 *    d = a + b + c;
 *    System.out.println("a = " + a);
 *    System.out.println("b = " + b);
 *    System.out.println("c = " + c);
 *    System.out.println("d = " + d);
 *   }
 * }
 * 3.编写一个应用程序,读取用户输入的3个非零数据,判断并输出这三个数据能否构成一个三角形。
 * 4.用switch语句编写一个完成两个整数四则运算的程序。
 * 5.编写应用程序,求1 * 1 - 2 * 2 + 3 * 3 - 4 * 4 + ...... — 100 * 100的值。
 * 6.编写应用程序,求1! + 2! + ...... + 20!的和并显示,同时输出1!、2!、3!...的结果。
 * */
package ch3;
 
/*public class Example {
 
 public static void main(String[] args) {
  int a = 20, b = 50, c = 100, d;
  a %= 9;
  b /= 7;
  c %= b;
  d = a + b + c;
  System.out.println("a = " + a);
  System.out.println("b = " + b);
  System.out.println("c = " + c);
  System.out.println("d = " + d);
 }
}*/
/*import java.util.Scanner;
 * public class PanDuanSanJiao {
 public static void main(String[] args) {
  Scanner s = new Scanner(System.in);
  System.out.println("请输入三个整数");
  int a = s.nextInt();
  int b = s.nextInt();
  int c = s.nextInt();
  if(a < 0 || b < 0 || c < 0) {
   System.out.println("请输入正数");
  }else if(a + b > c & a + c > b & b + c > a) {
   System.out.println("可以构成三角形");
  }
 }
}*/
/*public class SiZeYunSuan {
 public static void main(String[] args) {
  int a = 10;
  int b = 20;
  char operator = '+';
  switch(operator) {
  case '+':
   System.out.println(a + "+" + b + " = " + (a + b));
   break;
  case '-':
   System.out.println(a + "-" + b + " = " + (a - b));
   break;
  case '*':
   System.out.println(a + "*" + b + " = " + (a * b));
   break;
  case '/':
   System.out.println(a + "/" + b + " = " + (a / b));
   break;
   default:
    System.out.println("-1");
  }
 }
}*/
/*public class QiuZhi {
 public static void main(String[] args) {
  int sum = 0;
  for(int i = 1; i <= 100; i ++) {
   if(i % 2 == 1) {
    sum += i * i;
   }else {
    sum -= i * i;
   }
  }
  System.out.println("和是" + sum);
 }
}*/
/*public class JC {
 public static void main(String[] args) {
  long sum = 0;
  long result = 1;
  for(int i = 1; i <= 20; i ++) {
   result *= i;
   System.out.println(i + "的阶乘是:" + result);
   sum += result;
  }
  System.out.println("1到20的阶乘和是:" + sum);
 }
}*/
补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,