java新手,怎么将字符串转变为*号
输入字符串,但在屏幕上只显示*号,应该怎么做?求举例
不太明白什么意思
都显示*号的话
String str="字符串";
String str2="";
for(i=0;i<str.length;i++)
{
str2+="*";
}
str=str2;
import java.util.Scanner; public class Test{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(true){ String s=sc.next(); if(s.equals("over")) break; for (int i = 0; i < s.length(); i++) { System.out.print("*"); } System.out.println(); } System.out.println("Test结束……"); } }
import *; import java.util.*; public class 无回显密码输入 { public static void main(String[] args) { Console console = System.console(); if (console == null) { System.err.println("Failed to get console!"); return; } String name = console.readLine("Please type your name:"); char[] password1 = null; char[] password2 = null; console.printf("Your name is %s\n", name); password1 = console.readPassword("Please type your password:"); password2 = console.readPassword("Please type your password again:"); if (!Arrays.equals(password1, password2)) { System.err.println("Password doesn't match the confirmation."); return; } console.printf("Hi, %s, Your password is '%s'\n", name, new String(password1)); Arrays.fill(password1, '\0'); /* 安全清理 */ Arrays.fill(password2, '\0'); } }只支持原生的控制台,像eclipse的控制台是不行的……找不到回显为*的功能……
#include<stdio.h> #include<conio.h> int main(void) { char a[1000]; printf(" 输入为 * 结束"); printf("\n"); int i=0; while(true){ a[i]=getch(); if(a[i]=='*') break; putchar('*'); i++; } printf("\n"); /*显示*/ printf("输入的是:\n"); for(int j=0;j<i;j++){ printf("%c",a[j]); } printf("\n"); return 0; }c语言好实现