第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不是聲明;預(yù)計

不是聲明;預(yù)計

千萬里不及你 2023-06-21 13:26:18
不是聲明;預(yù)期的我試圖將輸入的值放入數(shù)組中。但它說的不是聲明我是編程新手,我正在嘗試自學(xué) javaimport java.util.Scanner;public class MainClass {    public static void main(String[] args){        int[] studID = new int[100];        String[] Lname = new String[100];        String[] Fname = new String[100];        String[] studProgram = new String[100];        int[] studYear = new int[100];        System.out.println("1. add student");        System.out.println("2. view student");        System.out.println("3. edit student");        System.out.println("4. delete student");        System.out.print("Please choose: ");        Scanner scan = new Scanner(System.in);        int choice = scan.nextInt();        switch(choice){            case 1:                System.out.print("Enter ID: ");                studID[] = scan.nextInt();                System.out.print("Enter Last name: ");                Lname[] = scan.next();                System.out.print("Enter First name: ");                Fname[] = scan.next();                System.out.print("Enter Course: ");                studProgram[] = scan.next();                System.out.print("Enter Year: ");                studYear[] = scan.nextInt();            case 2:                 System.out.println("Enter student ID to view: ");                 int studView = scan.        }    } }我期望當(dāng)我將學(xué)生的值放入數(shù)組中時,如果我選擇查看學(xué)生ID,它還會顯示依賴學(xué)生ID的學(xué)生的其他信息
查看完整描述

4 回答

?
牧羊人nacy

TA貢獻1862條經(jīng)驗 獲得超7個贊

您不能將 an 分配int給整個數(shù)組

studID[] = scan.nextInt();

您需要做的是將其分配給數(shù)組的一個元素,例如

studID[0] = scan.nextInt();

或者

studID[i] = scan.nextInt();

i索引在哪里

因為你沒有循環(huán)或使用多個值,為什么你甚至有數(shù)組?


查看完整回答
反對 回復(fù) 2023-06-21
?
波斯汪

TA貢獻1811條經(jīng)驗 獲得超4個贊

給定代碼,您不需要數(shù)組來存儲字符串或整數(shù):


int[] studID = new int[100];

String[] Lname = new String[100];

String[] Fname = new String[100];

String[] studProgram = new String[100];

int[] studYear = new int[100];

只需像這樣聲明它們:


int studID;

String Lname;

String Fname;

String studProgram;

int studYear;

在這個開關(guān)盒中:


switch(choice){


        case 1:

            System.out.print("Enter ID: ");

            studID = scan.nextInt();


            System.out.print("Enter Last name: ");

            Lname = scan.next();


            System.out.print("Enter First name: ");

            Fname = scan.next();


            System.out.print("Enter Course: ");

            studProgram = scan.next();


            System.out.print("Enter Year: ");

            studYear = scan.nextInt();



    }

nextInt() 方法返回一個整數(shù),而不是一個數(shù)組,next() 返回一個字符串,而不是字符串?dāng)?shù)組。如果您需要任何幫助,我們非常樂意為您提供幫助。


查看完整回答
反對 回復(fù) 2023-06-21
?
交互式愛情

TA貢獻1712條經(jīng)驗 獲得超3個贊

你在這里做錯了幾件事。首先,它應(yīng)該是這樣的。; 預(yù)期在 java 中結(jié)束語句而不是 .(點)。


int studView = scan.nextInt();

現(xiàn)在,您插入數(shù)組元素的邏輯不正確。您必須知道,數(shù)組是存儲在特定索引處的許多元素的集合。因此,您需要將 scan.nextInt() 中的 elem 存儲在特定索引處。為了那個原因,


for(int i=0;i<someLength;i++){

 int choice = scan.nextInt();

  switch(choice){

   case 1:

        System.out.print("Enter ID: ");

            studID[i] = scan.nextInt(); // This i is important here to store at some particular index

   ......................

....................

    }

  }


查看完整回答
反對 回復(fù) 2023-06-21
?
臨摹微笑

TA貢獻1982條經(jīng)驗 獲得超2個贊

除了其他答案之外,如果您計劃動態(tài)地向其添加整數(shù),那么使用ArrayList可能會更好。它不需要預(yù)先確定的大小,并允許您將一個整數(shù)添加到數(shù)組的末尾。希望這可以幫助。



查看完整回答
反對 回復(fù) 2023-06-21
  • 4 回答
  • 0 關(guān)注
  • 214 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號