Java静态方法问题 [英] Java static method question

查看:97
本文介绍了Java静态方法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

构建一个presidentnts()方法,打印出美国前七位总统的名字,每个都在不同的行上。请记住使您的方法成为静态方法。让main方法调用presidents()方法。打电话给你的班级PresClass



我的尝试:



就像我对如何为这个问题编写代码感到困惑。就像我必须使用return语句来使其工作

这里我的代码:

  public   class  PresClass {
public static 字符串 {
public static void 总统( String args []){
系统。 out.print( George Washington);
System.out.print( John Adams);
System.out.print( Thomas Jefferson);
System.out.print( James Madison);
System.out.print( James Monroe);
System.out.print( John Quincy Adams);
System.out.print( Andrew Jackson);
}

解决方案

要求很明确,你必须填写以下骨架

< pre lang =java> class PresClass
{
static void 总统()
{
// ..
// 此处的代码
// ..
}
public 静态 void main( String args [])
{
presidents();
}
}


Build a presidents() method that prints out the names of the first 7 Presidents of the United States, each on separate lines. Remember to make your method a static method. Have your main method call the presidents() method. Call your class "PresClass"

What I have tried:

Like I'm getting confuse of how to make my code for this question. Like do I have to put a return statement to make it work
Here my code:

public class PresClass { 
public static String {
public static void presidents(String args[]) {
System.out.print("George Washington");
System.out.print("John Adams");
System.out.print("Thomas Jefferson");
System.out.print("James Madison");
System.out.print("James Monroe");
System.out.print("John Quincy Adams");
System.out.print("Andrew Jackson");
}

解决方案

The requirements are clear, you have to fill the following skeleton

class PresClass
{
  static void presidents()
  {
    //.. 
    // your code here
    //..
  }
  public static void main( String args[] )
  {
    presidents();
  }
}


这篇关于Java静态方法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆