//修改密码 public int update() { System.out.println("输入Id"); int businessId1=sc.nextInt(); System.out.println("修改后密码:"); String password1=sc.nextLine(); // BusinessDao rr=new BusinessDaoImpl(); Business uu=new Business(); uu.setBusinessId(businessId1); uu.setPassword(password1); return businessDao.updateBusinessPassword(password1,businessId1); }
时间: 2024-03-18 07:43:14 浏览: 12
这段代码是一个修改商家密码的方法。它会首先让用户输入商家ID和新的密码,然后创建一个Business对象,将输入的商家ID和新密码设置为对象的属性。接着调用BusinessDao中的updateBusinessPassword方法,将新密码和商家ID作为参数传入,来更新商家密码。最终返回更新成功的记录数。
相关问题
public class VariableDemo { int a = 111; final int b = 222; public void display() { System.out.println("执行display()"); int a = 333; System.out.println(a); System.out.println(this.a); System.out.println(b); System.out.println(this.b); } public static void main(String[] args) { // TODO Auto-generated method stub int a = 444; System.out.println("执行main()"); System.out.println(a); //System.out.println(this.a); {// 代码块1 int c = 666; System.out.println(c); } System.out.println(c); {// 代码块2 int d = 666; System.out.println(d); } int d = 888; System.out.println(d); VariableDemo vd = new VariableDemo(); vd.display(); vd.b = 999; System.out.println(vd.b); } }
该代码存在以下问题:
1. 在`main`方法中,不能直接访问非静态变量`a`和`b`,因为它们是属于对象的,必须先创建一个类的实例才能访问。
2. `final`修饰的变量`b`不能被修改,所以在`vd.b = 999;`中会编译错误。
3. 在代码块1中定义的变量`c`只能在代码块内部访问,超出代码块范围后就不能再访问了。在`System.out.println(c);`处会编译错误。
4. 变量名`d`在代码块2和`main`方法中都出现了,这是不合法的,因为在同一级作用域中变量名不能重复。
修正后的代码如下:
```
public class VariableDemo {
int a = 111;
final int b = 222;
public void display() {
System.out.println("执行display()");
int a = 333;
System.out.println(a);
System.out.println(this.a);
System.out.println(b);
System.out.println(this.b);
}
public static void main(String[] args) {
int a = 444;
System.out.println("执行main()");
System.out.println(a);
{
int c = 666;
System.out.println(c);
}
// System.out.println(c); // 编译错误
{
int d = 666;
System.out.println(d);
}
int d = 888;
System.out.println(d);
VariableDemo vd = new VariableDemo();
vd.display();
// vd.b = 999; // 编译错误
System.out.println(vd.b);
}
}
```
修正后的代码中,将`vd.b = 999;`注释掉,因为`b`是用`final`修饰的,不能被修改。同时,变量名重复的问题也得到了修正。
Scanner sc = new Scanner(System.in); System.out.println("请输入你要修改的学生学号:"); int number = sc.nextInt();
这是一个 Java 代码片段,用于从控制台读取用户输入的学生学号,以便后续修改该学生的信息。首先,`Scanner` 类的对象 `sc` 被创建,它可以用来读取控制台输入。`System.in` 表示从标准输入流中读取数据,即从控制台读取数据。然后,`System.out.println()` 方法被调用,向控制台输出一条提示信息,要求用户输入要修改的学生学号。接着,`sc.nextInt()` 方法被调用,用于读取用户输入的整数,即学生学号,并将其赋值给 `number` 变量。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)