我希望年龄乘以3这是我的代码要求用户输入姓名和年龄......................... ......................
import java.util.Scanner;
class Lab1Part4 {
public static void main (String [] args) {
Scanner user_input =
int tripleAge;
String printMyName;
String firstName;
String secondName;
System.out.println("Please enter your first name ? ");
firstName = user_input.next ();
System.out.println("Please enter your second name? ");
secondName = user_input.next ();
printMyName = firstName + " " + secondName;
System.out.println( printMyName);
System.out.println("Enter your age ? ");
tripleAge = user_input.nextInt ();
}// end class
} //结束主要
答案 0 :(得分:2)
您只需要执行以下操作:
tripleAge = user_input.nextInt () * 3;
System.out.println(tripleAge);
答案 1 :(得分:0)
使用*
运算符进行乘法运算。
tripleAge = (user_input.nextInt () * 3);
System.out.println(tripleAge);