gpt4 book ai didi

java - 输入和循环

转载 作者:行者123 更新时间:2023-12-02 00:42:52 25 4
gpt4 key购买 nike

我正在尝试按照图片所示进行操作: enter image description here

这是我的代码:

import java.util.Scanner;
public class IcsProject
{

public static void main(String [] args)
{
Scanner keyboard= new Scanner (System.in);
int menuNum,ID,semNum,semCode,semCourses;

do{
System.out.println("Please Enter your Choice from the menu:");
System.out.println("1. Enter Student Sanscript");
System.out.println("2. Display Transcript Summary");
System.out.println("3. Read Student Franscript from a File");
System.out.println("4. Write Transcript Summary to a File");
System.out.println("5. Exit");

menuNum = keyboard.nextInt();

if (menuNum == 2 || menuNum == 3 || menuNum == 4)
System.out.println("Not working");


} while (menuNum > 1 && menuNum < 5);

//// Option 1: Enter student transcript


if (menuNum == 1)
System.out.println("Please enter your student's FIRST and LAST name:");
String stuName = keyboard.nextLine();
System.out.println("Please enter the ID number for " + stuName);
ID = keyboard.nextInt();
System.out.println("Please enter the number of semesters");
semNum = keyboard.nextInt();
for(int i=1 ; i < semNum ; i++)
{System.out.println("Please enter semester code for semester n# " + semNum);
semCode = keyboard.nextInt();
System.out.println("Please enter the number of courses taken in " + semCode );
semCourses = keyboard.nextInt();}
System.out.println("Enter course code, credit hours, and letter grade ")

///I stopped here
}
  • 我必须从学期代码开始使用数组吗?请给我举个例子。
  • 输入所有值后,程序应再次显示菜单,以便我可以从中进行选择。如何做到这一点?
  • 我在第一个问题“输入学生的名字和姓氏”时遇到问题程序会跳过它并转到下一个问题。我的 keyboard.nextLine();
  • 是否有错误

最佳答案

我将使用一个对象列表,其中包含您要记录的所有字段。

举个例子,就用google吧。

http://www.google.com/search?q=java+list+examples 2790 万条结果

http://www.google.com/search?q=java+object+examples 1800 万个结果。

http://www.google.com/search?q=java+array+examples 1500 万个结果。

关于java - 输入和循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5848001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com