String strFirst = System.in.toString(); //strFirst想得到键入的字符串,如何实现?
public class dh01_01
{
public static void main(String args[])
{
System.out.println("please input the first:");
String strFirst = System.in.toString();
System.out.println("the first string is:" + strFirst);
}
}
public class dh01_01
{
public static void main(String args[])
{
System.out.println("please input the first:");
String strFirst = System.in.toString();
System.out.println("the first string is:" + strFirst);
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String strFirst = s.next();
System.out.println(strFirst);
}
}
* @param args
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("input : (exit to out)");
String line = "";
while (!"exit".equals((line=scanner.nextLine()))) {
System.out.println("line : " + line);
System.out.println();
}
}
}
可以连续输入,只要不是exit
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in); System.out.println("please input the first:");
String strFirst = scan.next();
System.out.println("the first string is:" + strFirst); System.out.println("please input the second:");
String strSecond = scan.next();
System.out.println("the second string is:" + strSecond);
System.out.println("please input the third:");
String strThird = scan.next();
System.out.println("the third string is:" + strThird); int iFirst = Integer.parseInt(strFirst);
int iSecond = Integer.parseInt(strSecond);
int iFinal = 0;
boolean bGet = false;
if (0 == strThird.compareToIgnoreCase("+"))
{
iFinal = iFirst + iSecond;
bGet = true;
}
else if (0 == strThird.compareToIgnoreCase("-"))
{
iFinal = iFirst - iSecond;
bGet = true;
}
else if (0 == strThird.compareToIgnoreCase("-"))
{
iFinal = iFirst - iSecond;
bGet = true;
}
else if (0 == strThird.compareToIgnoreCase("*"))
{
iFinal = iFirst * iSecond;
bGet = true;
}
else if (0 == strThird.compareToIgnoreCase("/"))
{
iFinal = iFirst / iSecond;
bGet = true;
}
if (bGet)
{
System.out.println("the final value is:" + iFinal);
}
else
{
System.out.println("something is wrong");
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("input : (exit to out)");
String line = "";
while (!"exit".equals((line=scanner.nextLine()))) {//换行的时候
System.out.println("line : " + line);
System.out.println();
} }
}
public class dh01_01
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("please input the first:"); String strFirst = in.nextLine();
System.out.println("the first string is:" + strFirst);
}
}
int iSecond = scan.nextInt();