我是靠谱客的博主 淡然香氛,最近开发中收集的这篇文章主要介绍Java 实验课留的作业,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 

《Java程序设计》实验报告
学号: 04043351-25  姓名:王兆明       日期: 2007 4 16
题目: JAVA 基本用法与数组的使用
实验环境:
      Jdk 6.0 for Windows
     
实验内容与完成情况:
import java.io.*;
import java.util.*;
 
//
// 作业 1: 输出 1000 以内能被 17 23 整除的所有整数
 
class Hw_1
{
         public static void main(String[] args)
         {
                   for(int i=0;i<=1000;i++)
                   {
                            if(i%17==0&&i%23==0)
                                     System.out.println(i);
                   }
         }
}
//
/* 作业 2 :输出
            A
          B C
          D E F
         H I J K
         L M N O
          P Q R
          R S
            T
*/
 
class Hw_2
{
         public static void main(String[] args)
         {
                   char a='A';
                   for(int i=1;i<=4;i++)
                   {
                            for(int k=4;k>=i;k--)
                            {
                                     System.out.print(" ");
                            }
                            for(int j=1;j<=i;j++)
                            {
                                    
                                     System.out.print(a+" ");
                                     a++;
                            }
                            System.out.print('/n');
                   }
                   for(int i=4;i>=1;i--)
                   {
                            for(int k=4;k>=i;k--)
                            {
                                     System.out.print(" ");
                            }
                            for(int j=1;j<=i;j++)
                            {
                                     System.out.print(a+" ");
                                     a++;
                            }
                            System.out.print('/n');
                   }
                  
         }
}
//
// 作业 3 3 个整数中选取最大值和最小值
//import java.io.*;
//import java.util.*;
class Hw_3
{
         public static void main(String[] args)
         {
                   int[] a=new int[3];
                   String s;
                   BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                   System.out.println("please input three number");
                   for(int i=0;i<=2;i++)
                   {
                            try{
                                     a[i]=new Integer(in.readLine()).intValue();
                            }
                            catch(Exception e)
                            {
                                     a[i]=0;
                            }
                   }
                   Arrays.sort(a);
                   System.out.println("Max:"+a[2]);
                   System.out.println("Min:"+a[0]);
         }
}
 
//
// 作业 4: 水仙花数是三位数,各个数字的立方和等于数字本省
 
class Hw_4
{
         public static void main(String[] args)
         {
                   for(int i=100;i<=999;i++)
                   {
                            if(Math.pow(i%10,3)+Math.pow((i/10)%10,3)+Math.pow((i/100)%10,3)==i)
                            System.out.println("The number is "+i);
                   }
         }
}
 
 
//20 长度的数组,一次赋值 1~20, 计算数组下标为奇数的元素之和
class Hw_2_1
{
         public static void main(String[] args)
         {
                   int[] a=new int[20];
                   for(int i=1;i<=20;i++)
                   {
                            a[i-1]=i;
                   }
                   int sum=0;
                   for(int i=1;i<=20;i++)
                   {
                            if(i%2!=0)
                            {
                                     sum=sum+a[i];
                            }
                   }
                   System.out.println(sum);
         }
}
 
// 比较两个数组 arr1={2,4,6,8,10} arr2={3,5,7,9,11,13,15,17} 长度,然后用长度短的覆盖长度长的前几项,输出到屏幕上。
 
class Hw_2_2
{
         public static void main(String[] args)
         {
                   int[] arr1={2,4,6,8,10};
                   int[] arr2={3,5,7,9,11,13,15,17};
                  
                   if(arr1.length>=arr2.length)
                   {
                            for(int i=0;i<=arr2.length-1;i++)
                            {
                                     arr1[i]=arr2[i];
                            }
                            for(int i=0;i<=arr1.length-1;i++)
                                     System.out.println(arr1[i]);
                   }else
                   {
                            for(int i=0;i<=arr1.length-1;i++)
                            {
                                     arr2[i]=arr1[i];
                            }
                            for(int i=0;i<=arr2.length-1;i++)
                                     System.out.println(arr2[i]);
                   }
                  
         }
}
 
 
// 计算二维数组各个元素的和, arr 数组有 3 4 列。
class Hw_2_3
{
         public static void main(String[] args)
         {
                   int[][] arr={{1,2,3,4},{11,22,33,44},{111,222,333,444}};
                   int sum=0;
                   for(int i=0;i<=2;i++)
                   {
                            for(int j=0;j<=3;j++)
                            {
                                     sum=sum+arr[i][j];
                            }
                   }
                   System.out.println(sum);
         }
}
 

最后

以上就是淡然香氛为你收集整理的Java 实验课留的作业的全部内容,希望文章能够帮你解决Java 实验课留的作业所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(28)

评论列表共有 0 条评论

立即
投稿
返回
顶部