Chapter 6 homework after class
: computer practice 1
package tz1;
: computer practice 1
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);
}
}
}
Hands -on exercise 4 Verify user login information
package tz1;
package tz1;
import java.util.Scanner;
/*
* Hands-on exercise 4 to verify user login information
*/
public class dome2 {
public static void main(String[] args) {
String name ;//Define username
String password ;//Define user Password
int fas = 3;//Define the number of wrong
input Scanner input = new Scanner(System.in);
for (int i = 1; i <= 3; i++) {
System.out.println("Please enter the user name :");
name = input.next();
/*
* Hands-on exercise 4 to verify user login information
*/
public class dome2 {
public static void main(String[] args) {
String name ;//Define username
String password ;//Define user Password
int fas = 3;//Define the number of wrong
input Scanner input = new Scanner(System.in);
for (int i = 1; i <= 3; i++) {
System.out.println("Please enter the user name :");
name = input.next();
System.out.println("Please enter password:");
password = input.next();
if (name.equals("jim") || password.equals("123456")) {
System.out.println( "Welcome to log in to the system");
break;
}
if (i == 3) {
System.out.println("Sorry, you entered the wrong input 3 times");
break;
} else {
System.out.println("Incorrect input ! You still have " + (fas - i) + "chance");
password = input.next();
if (name.equals("jim") || password.equals("123456")) {
System.out.println( "Welcome to log in to the system");
break;
}
if (i == 3) {
System.out.println("Sorry, you entered the wrong input 3 times");
break;
} else {
System.out.println("Incorrect input ! You still have " + (fas - i) + "chance");
continue;
}
}
}
}
}
}
}
Short Answer Question
1 Calculate the average study time from Monday to Friday
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("Please enter the learning time of the week"+(i+1)+":");
double time = input.nextDouble();
total += time;
}
System.out.println("The average study time from Monday to Friday is "+total/5.0+"hours");
}
Short Answer Question
1 Calculate the average study time from Monday to Friday
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("Please enter the learning time of the week"+(i+1)+":");
double time = input.nextDouble();
total += time;
}
System.out.println("The average study time from Monday to Friday is "+total/5.0+"hours");
}
}
2 Find the number of chickens and rabbits
package com.bdqn.dome;
2 Find the number of chickens and rabbits
package com.bdqn.dome;
public class dome9 {
public static void main(String[] args) {
int chookNum, rabitNum;
for (chookNum = 0; chookNum < 35; chookNum++) {
// chicken equals 0 chicken is less than 35 chicken count plus 1
// rabbit's The number is equal to 35 minus the number of chickens
rabitNum = 35 - chookNum;
if (2 * chookNum + 4 * rabitNum == 94) {
public static void main(String[] args) {
int chookNum, rabitNum;
for (chookNum = 0; chookNum < 35; chookNum++) {
// chicken equals 0 chicken is less than 35 chicken count plus 1
// rabbit's The number is equal to 35 minus the number of chickens
rabitNum = 35 - chookNum;
if (2 * chookNum + 4 * rabitNum == 94) {
System.out.println("chicken has" + chookNum + "only, no" + rabitNum + "only");
}
}
}
}
}
3. FlipFlop game
package com.bdqn.dome;
}
3. FlipFlop game
package com.bdqn.dome;
//Develop a game titled "flipfoip"
public class dome10 {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {// if divisible by 3 and divisible by 5
System.out.println("flipfoip");// output 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) {// if divisible by 3 and divisible by 5
System.out.println("flipfoip");// output 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. Number of men, women, children.
package com.bdqn.dome;
4. Number of men, women, children.
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);
}
}
}
}
}
}
}
}
}