急急急,求JAVA大神 25
编写程序,读入任一个整数并将其各位数字之和赋给一个整数并输出各位上数字和数字和。源字符串:abcdefg,编写一个程序实现字符串的转置,使字符串变为gfedcba。要求字...
编写程序,读入任一个整数并将其各位数字之和赋给一个整数并输出各位上数字和数字和。
源字符串:abcdefg,编写一个程序实现字符串的转置,使字符串变为gfedcba。要求字符串从键盘读入。
统计输入字符串中单词的个数。
JAVA的题目。。。急急急 在线等
这是三道题目 不知道为什么没打上编号。。。 展开
源字符串:abcdefg,编写一个程序实现字符串的转置,使字符串变为gfedcba。要求字符串从键盘读入。
统计输入字符串中单词的个数。
JAVA的题目。。。急急急 在线等
这是三道题目 不知道为什么没打上编号。。。 展开
3个回答
展开全部
这是三道题的main方法,我是用一个类写的,所以你自己分别建个类放下吧
1.
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String numStr = br.readLine();
long inputNumber = Long.parseLong(numStr);
int result = 0;
byte eachNumber = (byte) (inputNumber % 10);
long remainingNumber = inputNumber / 10;
while (remainingNumber > 0){
result += eachNumber;
eachNumber = (byte) (remainingNumber % 10);
remainingNumber = remainingNumber / 10;
}
result += eachNumber;
System.out.println(inputNumber + ", sum of each number is " + result);
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2.
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String inputStr = br.readLine();
char[] chars = inputStr.toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = chars.length - 1; i>=0; i--) {
sb.append(chars[i]);
}
System.out.println("result is: " + sb.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
3.
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String inputStr = br.readLine();
inputStr = inputStr.replaceAll("[,.'\"!;\\?]","");
int result = inputStr.split("\\s+").length;
System.out.println("number of words is: " + result);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2014-05-21 · 知道合伙人数码行家
关注
展开全部
//1、
public class static Sum{
public static void main(String[] args){
java.util.Scanner sc = new java.util.Scanner(System.in);
try{
int sum = 0;
System.out.println("请输入数字的数量");
int[] arr = new int[sc.nextInt()];
for(int i = 0; i < arr.length; i++){
System.out.println("请输入数字,目前不支持小数");
arr[i] = sc.nextInt();
sum += arr[i];
}
System.out.println("总和为:" + sum);
}catch(Exception e){
System.err.println("您输入的不是数字");
}
}
}
//2、
public class Reverse{
public static void main(String[] args){
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println("请输入字符串...");
StringBuilder sb = new StringBuilder(sc.next());
System.out.println("反转后为:" + sb.reverse());
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Class Account{
private int id;
private double balance;
private double annuallnterestRate;
private Date dateCreated;
public Account(){
this.id = 0;
this.balance = 0;
this.annuallnterestRate = 0;
this.dateCreated = new Date();
}
public Account(int id, double balance){
this.id = id;
this.balance = balance;
this.dateCreated = new Date();
}
public int getId(){
return this.id;
}
public void setId(int id){
this.id = id;
}
public double getBalance(){
return this.balance
}
public void setBalance(double balance){
this.balance = balance;
}
public double getAnnuallnterestRate(){
return this.annuallnterestRate
}
public void setAnnuallnterestRate(double annuallnterestRate){
this.annuallnterestRate = annuallnterestRate
}
public Date getDateCreated(){
return this.dateCreated;
}
public double getMonthlyInterestRate(){
double monthlyInterest = java.lang.StrictMath.pow(this.annuallnterestRate,1.0/12)-1;
return monthlyInterest;
}
public String withdraw(double amount){
this.balance = this.balance-amount;
return "withdraw success";
}
public String deposit(double amount){
this.balance = this.balance+amount;
return "deposit success";
}
public static void main(String[] args){
Account account = new Account(1122,20000.00);
account.setAnnuallnterestRate(0.045);
account.withdraw(2500.00);
account.deposit(3000.00);
System.out.println(account.getBalance());
System.out.println(account.getMonthlyInterestRate());
System.out.println(account.getDateCreated());
}
}
不谢!分数拿来~
private int id;
private double balance;
private double annuallnterestRate;
private Date dateCreated;
public Account(){
this.id = 0;
this.balance = 0;
this.annuallnterestRate = 0;
this.dateCreated = new Date();
}
public Account(int id, double balance){
this.id = id;
this.balance = balance;
this.dateCreated = new Date();
}
public int getId(){
return this.id;
}
public void setId(int id){
this.id = id;
}
public double getBalance(){
return this.balance
}
public void setBalance(double balance){
this.balance = balance;
}
public double getAnnuallnterestRate(){
return this.annuallnterestRate
}
public void setAnnuallnterestRate(double annuallnterestRate){
this.annuallnterestRate = annuallnterestRate
}
public Date getDateCreated(){
return this.dateCreated;
}
public double getMonthlyInterestRate(){
double monthlyInterest = java.lang.StrictMath.pow(this.annuallnterestRate,1.0/12)-1;
return monthlyInterest;
}
public String withdraw(double amount){
this.balance = this.balance-amount;
return "withdraw success";
}
public String deposit(double amount){
this.balance = this.balance+amount;
return "deposit success";
}
public static void main(String[] args){
Account account = new Account(1122,20000.00);
account.setAnnuallnterestRate(0.045);
account.withdraw(2500.00);
account.deposit(3000.00);
System.out.println(account.getBalance());
System.out.println(account.getMonthlyInterestRate());
System.out.println(account.getDateCreated());
}
}
不谢!分数拿来~
追问
这是怎么分的。。。?上面那是三道题目。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询