联系方式
学习资讯
JAVA编程语言基础第六章
JAVA编程语言基础第六章
上机练习1
package tz1;
package tz1;
public class dome1 {
public static void main(String[] args) {
int sum=0;
for (int num =1; num<=99; num+=2) {
sum+=num;
System.out.println(sum);
}
}
public static void main(String[] args) {
int sum=0;
for (int num =1; num<=99; num+=2) {
sum+=num;
System.out.println(sum);
}
}
}
上机练习4 验证用户登入信息
package tz1;
package tz1;
import java.util.Scanner;
/*
* 上机练习4 验证用户登入信息
*/
public class dome2 {
public static void main(String[] args) {
String name ;//定义用户名
String password ;//定义用户密码
int fas = 3;//定义输错的次数
Scanner input = new Scanner(System.in);
for (int i = 1; i <= 3; i++) {
System.out.println("请输入用户名:");
name = input.next();
/*
* 上机练习4 验证用户登入信息
*/
public class dome2 {
public static void main(String[] args) {
String name ;//定义用户名
String password ;//定义用户密码
int fas = 3;//定义输错的次数
Scanner input = new Scanner(System.in);
for (int i = 1; i <= 3; i++) {
System.out.println("请输入用户名:");
name = input.next();
System.out.println("请输入密码:");
password = input.next();
if (name.equals("jim") || password.equals("123456")) {
System.out.println("欢迎登入系统");
break;
}
if (i == 3) {
System.out.println("对不起,您3次都输入错误");
break;
} else {
System.out.println("输入错误!您还有" + (fas - i) + "机会");
password = input.next();
if (name.equals("jim") || password.equals("123456")) {
System.out.println("欢迎登入系统");
break;
}
if (i == 3) {
System.out.println("对不起,您3次都输入错误");
break;
} else {
System.out.println("输入错误!您还有" + (fas - i) + "机会");
continue;
}
}
}
}
}
}
}
简答题
1计算周一到周五的平均学习时间
package com.bdqn.dome;
import java.util.Scanner;
public class dome8 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double total=0;
for (int i = 0; i < 5; i++) {
System.out.println("请输入周"+(i+1)+"的学习时间:");
double time = input.nextDouble();
total += time;
}
System.out.println("周一到周五平均学习时间是"+total/5.0+"小时");
}
简答题
1计算周一到周五的平均学习时间
package com.bdqn.dome;
import java.util.Scanner;
public class dome8 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double total=0;
for (int i = 0; i < 5; i++) {
System.out.println("请输入周"+(i+1)+"的学习时间:");
double time = input.nextDouble();
total += time;
}
System.out.println("周一到周五平均学习时间是"+total/5.0+"小时");
}
}
2求鸡和兔子数量
package com.bdqn.dome;
2求鸡和兔子数量
package com.bdqn.dome;
public class dome9 {
public static void main(String[] args) {
int chookNum, rabitNum;
for (chookNum = 0; chookNum < 35; chookNum++) {
// 鸡等于0 鸡小于35 鸡的数量加1
// 兔子的数量等于35减去鸡的数量
rabitNum = 35 - chookNum;
if (2 * chookNum + 4 * rabitNum == 94) {
public static void main(String[] args) {
int chookNum, rabitNum;
for (chookNum = 0; chookNum < 35; chookNum++) {
// 鸡等于0 鸡小于35 鸡的数量加1
// 兔子的数量等于35减去鸡的数量
rabitNum = 35 - chookNum;
if (2 * chookNum + 4 * rabitNum == 94) {
System.out.println("鸡有" + chookNum + "只,免有" + rabitNum + "只");
}
}
}
}
}
3.FlipFlop游戏
package com.bdqn.dome;
}
3.FlipFlop游戏
package com.bdqn.dome;
//开发一个标题为"flipfoip"的游戏
public class dome10 {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {// 如果能被3整除并且能被5整除
System.out.println("flipfoip");// 就输出flipfoip
} else if (i % 5 == 0) {
System.out.println("foip");
} else if (i % 3 == 0) {
System.out.println("flip");
} else {
System.out.println(i);
}
}
}
public class dome10 {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {// 如果能被3整除并且能被5整除
System.out.println("flipfoip");// 就输出flipfoip
} else if (i % 5 == 0) {
System.out.println("foip");
} else if (i % 3 == 0) {
System.out.println("flip");
} else {
System.out.println(i);
}
}
}
}
4.男人,女人,小孩的数量。
package com.bdqn.dome;
4.男人,女人,小孩的数量。
package com.bdqn.dome;
public class dome11 {
public static void main(String[] args) {
int man, women, kids;
for (kids = 1; kids <= 50; kids++) {
for (women = 1; women < 25; women++) {
for (man = 1; man < 16; man++) {
if (3 * man + 2 * women + kids == 50) {
if (man + women + kids == 30) {
}
System.out.println("男人有" + man + "女人有" + women + "小孩有" + kids);
}
public static void main(String[] args) {
int man, women, kids;
for (kids = 1; kids <= 50; kids++) {
for (women = 1; women < 25; women++) {
for (man = 1; man < 16; man++) {
if (3 * man + 2 * women + kids == 50) {
if (man + women + kids == 30) {
}
System.out.println("男人有" + man + "女人有" + women + "小孩有" + kids);
}
}
}
}
}
}
}
}
}
更多培训课程,学习资讯,课程优惠等学校信息,请进入 重庆IT培训重庆ITIL认证培训重庆Oracle数据库认证培训重庆思科认证培训 网站详细了解,免费咨询电话:400-998-6158