11.4 Homework

Job 1
import java.util.Scanner;
public class day8_05 { public static void main(String[] args){ System.out.println("MyShopping management system> customer information management> add customer information"); Scanner a=new Scanner (System.in); for(int i=1;i<4;i++){ System.out.print("\nPlease enter the membership number (<4 digits>):"); boolean chakan=a.hasNextInt (); if(chakan){ int hy=a.nextInt(); if(hy<1000||hy>9999){ System.out.println("input error"); continue; }else{ System.out. print("Please enter the member's birthday (month/day<represented by a two-digit integer>):"); String sr=a.next(); System.out.print("Please enter member points:"); String jf= a.next(); System.out.print("The member information you entered is:\n"+(hy)+"\t"+(sr)+"\t"+(jf)+"\n"); }


















}else{ String nazou=a.next(); System.out.println("Input error"); continue; } } System.out.println("End of program!"); } } Job 2 import java.util. Scanner;







Insert picture description here

public class lulu { public static void main(String[] args) { Scanner ipt =new Scanner(System.in); String userName = “root”; String password = “123123”; String entName; String entPassword; int i; for (i = 3; i>0;){ i–; System.out.print("Please enter the user name:"); entName = ipt.next(); System.out.print("Please enter the password:") ; entPassword = ipt.next(); if (!entName.equals(userName)||!entPassword.equals(password)){ System.out.println("Input error! You still have "+i+" second chance!" ); System.out.println(); continue; } System.out.println("Welcome to the MyShopping system!"); break; } if (i





















0){ System.out.println("Sorry, you entered incorrectly three times!"); } } } Job 3 import java.util.Scanner; public class day8_07 { public static void main(String[] args) { Scanner a=new Scanner(System.in); int fw=(int)(Math.random() 100+1); int money=50; System.out.println(" Guess the number game\nRules : initial amount 50 yuan , Every guess of a round of 10 yuan, guess the reward 30 yuan, each round has 6 chances, the number range is 0-100!"); for(;money>=10;){ money-=10; System.out.println( "\ nBalance (10 yuan has been paid by this bureau):"+money); System.out.print("*Number range 0-100!"); fw=(int)(Math.random()*100+1) ; for(int cishu=0;cishu<6;){ cishu++; boolean pd=a.hasNextInt();




Insert picture description here
















if(pd){
int cai=a.nextInt();
if(cai>0&&cai<100){
if(cai
fw){ System.out.println("*Congratulations on your guess! The first "+cishu+" second guess! Reward 30 yuan"); money+=30; cishu=6; }else if(cai>fw){ System .out.println("*big! Used times:"+cishu); }else{ System.out.println("*small! Used times:"+cishu); } }else{ System.out. println("*Please enter 0-100! Used times:"+cishu); } }else{ System.out.println("*Please enter an integer! Used times:"+cishu); String nazou=a.next (); } } if(money<10){ System.out.println("*Insufficient balance! Game over!"); } } } }





















Guess you like

Origin blog.csdn.net/zzxin1216/article/details/109509343