Java第七次作业
package shangjizuoye; public class keye { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int a[]=new int[]{10,20,30,40,50}; for (int i = 0; i < a.length; i++) { System.out.println(a[i]+""); } } }
2.
package shangjizuoye;
import java.util.Scanner;
public class keye2 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int []a=new int[5];
for (int i = 0; i < a.length; i++) {
a[i]=input.nextInt();
}
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
3.
package shangjizuoye;
public class keye3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String []a={"c","h","i","n","a"};
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]);
}
}
}
4.
package shangjizuoye;
import java.util.Scanner;
public class keye4 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
int []a=new int[5];
int sum=0;
double shu=0;
for (int i = 0; i < a.length; i++) {
a[i]=input.nextInt();
sum+=a[i];
}
shu=sum/5.0;
System.out.println("总分数为"+sum+"平均数为"+shu);
}
}
5.
package shangjizuoye;
public class keye5 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = new int []{12,53,23,44,53};
System.out.println("for输出");
for (int i = 0; i < a.length; i++) {
System.out.print(" "+a[i]);
}
System.out.println("\n"+"foreach输出");
for (int i : a){
System.out.print(" "+i);
}
System.out.println("\n"+"倒序输出");
for (int i = 4; i >=0; i--) {
System.out.print(" "+a[i]);
}
}
}
作业1.
package shangjizuoye;
public class zuoye1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[]=new int []{2,3,12,17,24};
int ji=0,ou=0;
for (int i = 0; i < a.length; i++) {
if(a[i]%2==0){
ou++;
}
if(a[i]%2!=0){
ji++;
}
}
System.out.println("奇数的个数为"+ji+"偶数的个数为"+ou);
}
}
作业2.
package shangjizuoye;
public class zuoye2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = new int [100];
for (int i = 0; i < a.length; i++) {
a[i]=i+1;
}
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
作业3.
package shangjizuoye;
import java.util.Scanner;
public class zuoye3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
double a[] = new double [10];
for (int i = 0; i < a.length; i++) {
a[i]=input.nextDouble();
}
for (int i = 0; i < a.length; i++) {
a[i]=a[i]+5;
if(a[i]>100){
a[i]=100;
}
}
System.out.println("加完5分后的成绩为");
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}